Voice Changes in Flash (lower)

Source: Internet
Author: User
Voice changing http://vivimice.blog.163.com/blog/static/16100120111111428742/ in Flash

Work 15:41:25 read 188 comments 12 font size: large and small subscriptions

As we said last time, the most simple algorithm for Voice conversion is to use FFT to transform audio signals to the frequency domain, and then extend the spectrum to the high frequency or contract to the low frequency. This article focuses on the Performance Evaluation and Optimization Methods of the above algorithms in Flash (ActionScript 3.

As we all know, as3 is a language compiled into ABC bytecode and then run on avm2, with the OO feature. ABC is very concise. avm2 is a lightweight Virtual Machine. as3 is very friendly in writing, but the execution efficiency is not outstanding, in particular, this computation-intensive algorithm (although FFT has simplified its complexity from O (N ^ 2) to O (nlogn ). First, we need to directly use as3 to implement a (FFT Implementation to rewrite the self-FFT. java). audio data can be directly read from 44100Hz/16 bit/MONO audio files (in PCM format). The configurable parameters include the frame length, the length of the frame overlap area, and the spectrum scaling factor. The implementation efficiency of pure as is not ideal. According to the 2048 points of each frame, the frames overlap 1024 points (overlap rate 50%), and the processing time is about 10 times the length of the input data, that is to say, it takes about 10 seconds to process the 1 second audio, and takes up the CPU time of the entire Flash Player. If you want to reserve time for the graphics rendering thread, the time will be longer. First, try to optimize the Code, such as reducing the degree of OO, optimizing the cycle, reducing repeated calculations, and using the look-up table method where the accuracy is not high, however, this optimization only improves the efficiency by about 5%, and the code's readability and maintainability are greatly reduced. Then I thought of Adobe's alchemy project. This is a tool chain that uses gcc/lvvm to compile C code into ABC bytecode, although I have been skeptical about how it can improve efficiency-although it is C code, but this is different from JNI and other mechanisms, alchemy will compile C code into intermediate code, then run on an as-implemented automatic machine on avm2, instead of local code like JNI (in a sense, the efficiency of intermediate code should be lower, because they are equivalent to running in an automation machine running on avm2 ). However, it turns out that my understanding is correct, but suspicion is unnecessary. First go to the Adobe website to download the alchemy tool chain (http://labs.adobe.com/technologies/alchemy/), find a Debian host installed, compiled into SWC code is no problem, but in the console can not run life and death, later I found that Adobe didn't provide the ADL in Linux. I found the ADL IN THE AIR SDK and it couldn't run. It had to be X. I developed it in windows. SSH is remotely compiled and run on the host. I really don't understand why the console's ADL requires X (I learned later, when an error occurs, use X instead of stderr to display the error stack ......), No way. You have installed another vncserver. By the way, some strange problems have been found in the middle. For details, please refer to http://savagelook.com/blog/actionscript3/adobe-alchemyto solve them later. After writing 88 code for so many years, the foundation of C has not been lost at all. It is easy to implement. First, you can directly use the console and alsa api to directly increase the audition effect on the host. For the sake of security, we also used valgrind to check for memory errors. Finally, refer to the c api of alchemy, compile it into SWC, and then reference it in the Flash project. The efficiency is quite good, and it has been improved a lot. After adding the voice signal, the sampling rate can be appropriately reduced to 11050Hz, so that the amount of information is reduced to 1/4. In this way, 15 seconds of data is only required on my machine ~ The processing can be completed in 4 seconds, which also utilizes the asynchronous calling mechanism of alchemy. The adjustment algorithm is executed in another thread and will not affect the work of the drawing rendering thread. If it can be exclusive, it will be more efficient (however, considering the user experience, the exclusive method is not used in the end). However, I do not know whether it is a problem with my code or alchemy tool chain is currently unstable, after calling the sound changing routine several times, the automatic opportunity generated by alchemy will be suspended, which looks like a memory access violation. However, after compilation, the problem cannot be identified. This problem has not been solved for a long time and cannot be found. Later, we can only package a layer of SwF outside SWC, and then embed it into the caller. Each call by the caller is reloaded with loader. After it is used up, it will be unloaded + GC. This ensures that the automatic machine (including the status and memory of all registers) is used during each call) will be re-generated and initialized once (by default, if SWC is referenced directly, the automatic machine will only initialize once during the library init). In fact, my previous doubts about alchemy are justified: alchemy uses gcc/lvvm to compile C code into an intermediate code, and then runs the code on an automatic machine provided by alchemy. This automatic machine runs on avm2 again. However, due to the Optimization strength of GCC (the-O3 parameter is used during compilation), the optimization space of the Code is fully utilized, therefore, the efficiency is higher than that implemented by pure as3. In the same logic, the use of alchemy tool chain is still implemented using pure as3, so you need to consider the code optimization space. If it is computation-intensive and has sufficient optimization space, you can use alchemy to implement it. Otherwise, pure as achieves high efficiency. For example, to draw a lot of genie on the screen, it must be as efficient (because alchemy uses as to call the drawing API ), A pure accumulative loop requires a high efficiency of pure as, because the translation of pure cyclic statements into ABC only requires several lines of commands. If you run them in an automatic machine, the loss is worth the candle. So far, the whole process of implementing voice sound through Flash has been described. These articles mainly discuss the basic principles, algorithm implementation, and the specific implementation techniques and optimization methods of voice changes in flash. There will inevitably be many mistakes in this article. You are welcome to discuss them together!

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.