9RIA.com天地会 - 论坛

返回列表 发帖

天地培训

9RIA天地会官方培训机构

Adobe官方认证培训中心

[酷东东] 悬赏 集众人之力破解 声音变速播放 发言者有奖

集众人之力破解 声音变速播放 发言者有奖
银两不再多少,贵在参与。本人每帖最多一次只能加 20 两纹银,
灌纯水的不加,只对参与精神表示感谢。
如果有谁一次破解。加银两 100 。


本人想做一个英语播放的AS程序,可以控制 mp3 的播放速度,
可以快速播放,也可以慢速放。
经网友帮助在外国网站上找到了相关代码,无耐本人英语文盲,一句也看不懂;
发帖在天地会,所多个QQ群未能解决;
经longxinke舵主提议,
决定拿出一个有效的破解方案,所有参与者全部加银两。

望本论坛的各位舵主能够给与一定的方便的各方面的支持。  帮助加一些银两或帮助翻译一下。

破解目标:
实现控制 mp3 声音高速的功能,把相关的 .as 类文件的功能
全都用中文分析出来,用中华人民共和国简体中文标明注释。

先上传要破解的工具,SWFDecompiler 4.3绿色中文版 里面包括要破解的文件 Main.swf 。
文件如下。




破解后的代码资源。


共享类以及网址:
http://code.google.com/p/popforge/
共享类库一并上传在这里:


class 所在路径
2007.09.27 PopforgeLibrary\src\de\popforge
2007.09.27 PopforgeLibrary\src\de\popforge\audio\output

破解方案:
一个类一个类,
一个函数一个函数的进行注释翻译
步步推进,相信一定会把控制声音的函数和类弄清楚他们是怎么调用的。

[ 本帖最后由 龙城flash 于 2008-9-25 09:31 编辑 ]
附件: 您需要登录才可以下载或查看附件。没有帐号?注册

天地人才库
方案第一步:
首选要破解的是 Sample.as 文件

所在路径
开源路径: de.popforge.audio.output.Sample.as
破解实例路径: com.splicemusic.audio.Sample.as

实例代码:
  1. package com.splicemusic.audio
  2. {

  3. public class Sample extends Object
  4. {
  5. public var r:Number;
  6. public var l:Number;

  7. public function Sample()
  8. {
  9. var _loc_1:int;
  10. r = 0;
  11. l = _loc_1;
  12. return;
  13. }// end function

  14. }
  15. }
复制代码
开源代码:

  1. /*
  2. Copyright(C) 2007 Andre Michelle and Joa Ebert
  3. PopForge is an ActionScript3 code sandbox developed by Andre Michelle and Joa Ebert
  4. http://sandbox.popforge.de
  5. This file is part of PopforgeAS3Audio.
  6. PopforgeAS3Audio is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 3 of the License, or
  9. (at your option) any later version.
  10. PopforgeAS3Audio is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program.  If not, see <http://www.gnu.org/licenses/>
  16. */
  17. package de.popforge.audio.output
  18. {
  19. /**
  20.   * The class Sample stores 2 Numbers
  21.   * as a representation of the current Sample amplitudes.
  22.   * Their value should be computed in range[-1,1]
  23.   *
  24.   * For Mono Samples use only left.
  25.   *
  26.   * @author Andre Michelle
  27.   */
  28. public class Sample
  29. {
  30.   /**
  31.    * The left amplitude of the Sample
  32.    */
  33.   public var left: Number;
  34.   /**
  35.    * The right amplitude of the Sample
  36.    */
  37.   public var right: Number;
  38.   /**
  39.    * Creates a Sample instance
  40.    *
  41.    * @param left The left amplitude of the Sample
  42.    * @param right The right amplitude of the Sample
  43.    */
  44.   public function Sample( left: Number = 0.0, right: Number = 0.0 )
  45.   {
  46.    this.left = left;
  47.    this.right = right;
  48.   }
  49.   
  50.   /**
  51.    * Returns a clone of the current Sample
  52.    */
  53.   public function clone(): Sample
  54.   {
  55.    return new Sample( left, right );
  56.   }
  57.   
  58.   public function toString(): String
  59.   {
  60.    return '{ left: ' + left + ' right: ' + right + ' }';
  61.   }
  62. }
  63. }
复制代码
开源的代码有两个参数,是两个声道,
实例代码,没有传的的参数。

希望翻译一下开源代码的相关注释。和开源代码的函数(方法)作用或功能。
实例代码为什么没有传入的参数。

这两个 Sample 类 全部翻译的最少加 20 两。



.

[ 本帖最后由 龙城flash 于 2008-9-24 17:02 编辑 ]

TOP

简单说跳帧就可以实现你的要求。控制跳帧多少,就可以达到控制变频速度了
曾经做过一个跳帧控制帧频的,不知道这个思路可否用到音频上。。。
1

评分人数

  • 龙城flash

龙城flash 赐本贴 银子 + 2  诏曰: 我也想过,你先做一个实例试一下。 ...

TOP

好兄弟,讲义气!---by eko

踏上天地会荣耀之路!

 

申请舵主

加入掘金队

加入译林军

知识专题整理

 

咨询(QQ):

1442604479(小地)

 

看源码,感觉是把音频数据转成byteArray后进行拉伸和缩短,应该不是简单的跳帧,而且跳帧会丢失很多数据,这应该不是楼主想要的效果。
1

评分人数

  • 龙城flash

龙城flash 赐本贴 银子 + 2  诏曰: 使用 byteArray 类可以进行深复制,这样改变 ...

TOP

方案第二步:
要破解的是 xxxxxBuffer.as 文件

所在路径

破解实例路径: com.splicemusic.audio.CycleBuffer.as
开源路径: de.popforge.audio.output.AudioBuffer.as

实例代码:


  1. package com.splicemusic.audio
  2. {
  3.     import flash.events.*;
  4.     import flash.media.*;
  5.     import flash.utils.*;
  6.     public class CycleBuffer extends ByteArray
  7.     {
  8.         private var bits:uint;
  9.         private var multiple:uint;
  10.         public var onComplete:Function;
  11.         private var buffer:Sound;
  12.         private var $byteCount:uint;
  13.         public var onInit:Function;
  14.         private var bufferChannel:SoundChannel;
  15.         private var sync:Sound;
  16.         private var channels:uint;
  17.         private var rate:uint;
  18.         private var $sampleCount:uint;
  19.         private var syncChannel:SoundChannel;
  20.         private var busy:Boolean;
  21.         public static const UNIT_SAMPLES_NUM:uint = 2048;
  22.         public function CycleBuffer(param1:uint, param2:uint, param3:uint, param4:uint)
  23.         {
  24.             this.multiple = param1;
  25.             this.channels = param2;
  26.             this.bits = param3;
  27.             this.rate = param4;
  28.             init();
  29.             return;
  30.         }// end function
  31.         public function stop() : void
  32.         {
  33.             if (syncChannel != null)
  34.             {
  35.                 syncChannel.stop();
  36.                 syncChannel = null;
  37.             }// end if
  38.             if (bufferChannel != null)
  39.             {
  40.                 bufferChannel.stop();
  41.                 bufferChannel = null;
  42.             }// end if
  43.             buffer = null;
  44.             busy = false;
  45.             return;
  46.         }// end function
  47.         private function init() : void
  48.         {
  49.             var _loc_1:ByteArray;
  50.             var _loc_2:int;
  51.             endian = Endian.LITTLE_ENDIAN;
  52.             switch(rate)
  53.             {
  54.                 case 44100:
  55.                 {
  56.                     $sampleCount = UNIT_SAMPLES_NUM * multiple;
  57.                     break;
  58.                 }// end case
  59.                 case 22050:
  60.                 {
  61.                     $sampleCount = UNIT_SAMPLES_NUM * multiple >> 1;
  62.                     break;
  63.                 }// end case
  64.                 case 11025:
  65.                 {
  66.                     $sampleCount = UNIT_SAMPLES_NUM * multiple >> 2;
  67.                     break;
  68.                 }// end case
  69.                 case 5512:
  70.                 {
  71.                     $sampleCount = UNIT_SAMPLES_NUM * multiple >> 3;
  72.                     break;
  73.                 }// end case
  74.                 default:
  75.                 {
  76.                     throw new Error("SamplingRate is not supported.");
  77.                     break;
  78.                 }// end default
  79.             }// end switch
  80.             $byteCount = $sampleCount;
  81.             if (channels == 2)
  82.             {
  83.                 $byteCount = $byteCount << 1;
  84.             }// end if
  85.             if (bits == 16)
  86.             {
  87.                 $byteCount = $byteCount << 1;
  88.             }// end if
  89.             _loc_1 = new ByteArray();
  90.             switch(bits)
  91.             {
  92.                 case 16:
  93.                 {
  94.                     _loc_1.length = sampleCount-- << 1;
  95.                     break;
  96.                 }// end case
  97.                 case 8:
  98.                 {
  99.                     _loc_1.length = sampleCount--;
  100.                     _loc_2 = 0;
  101.                     while (_loc_2 < _loc_1.length)
  102.                     {
  103.                         // label
  104.                         _loc_1[_loc_2] = 128;
  105.                         _loc_2++;
  106.                     }// end while
  107.                     break;
  108.                 }// end case
  109.                 default:
  110.                 {
  111.                     throw new Error("SamplingBits is not supported.");
  112.                     break;
  113.                 }// end default
  114.             }// end switch
  115.             SoundFactory.generate(_loc_1, 1, bits, rate, onGenerateSyncSound);
  116.             return;
  117.         }// end function
  118.         private function onGenerateSyncSound(param1:Sound) : void
  119.         {
  120.             sync = param1;
  121.             onInit(this);
  122.             return;
  123.         }// end function
  124.         public function isBusy() : Boolean
  125.         {
  126.             return busy;
  127.         }// end function
  128.         public function start() : void
  129.         {
  130.             busy = false;
  131.             if (sync != null)
  132.             {
  133.                 syncChannel = sync.play(0, 1);
  134.                 syncChannel.addEventListener(Event.SOUND_COMPLETE, onSyncComplete);
  135.                 if (bufferChannel != null)
  136.                 {
  137.                     bufferChannel.stop();
  138.                 }// end if
  139.                 if (buffer != null)
  140.                 {
  141.                     bufferChannel = buffer.play(0, 1);
  142.                 }// end if
  143.                 busy = true;
  144.             }// end if
  145.             return;
  146.         }// end function
  147.         private function onSyncComplete(param1:Event) : void
  148.         {
  149.             if (syncChannel != null)
  150.             {
  151.                 syncChannel.stop();
  152.             }// end if
  153.             syncChannel = sync.play(0, 1);
  154.             syncChannel.addEventListener(Event.SOUND_COMPLETE, onSyncComplete);
  155.             if (bufferChannel != null)
  156.             {
  157.                 bufferChannel.stop();
  158.             }// end if
  159.             if (buffer == null)
  160.             {
  161.                 return;
  162.             }// end if
  163.             bufferChannel = buffer.play(0, 1);
  164.             buffer = null;
  165.             onComplete(this);
  166.             return;
  167.         }// end function
  168.         public function fill(param1:Array) : void
  169.         {
  170.             var _loc_2:int;
  171.             var _loc_3:Sample;
  172.             switch(channels)
  173.             {
  174.                 case 1:
  175.                 {
  176.                     _loc_2 = 0;
  177.                     while (_loc_2 < $sampleCount)
  178.                     {
  179.                         // label
  180.                         _loc_3 = param1[_loc_2];
  181.                         if (_loc_3.l < -1)
  182.                         {
  183.                             writeShort(-32767);
  184.                         }
  185.                         else if (_loc_3.l > 1)
  186.                         {
  187.                             writeShort(32767);
  188.                         }
  189.                         else
  190.                         {
  191.                             writeShort(_loc_3.l * 32767);
  192.                         }// end else if
  193.                         _loc_3.l = 0;
  194.                         _loc_3.r = 0;
  195.                         _loc_2++;
  196.                     }// end while
  197.                     break;
  198.                 }// end case
  199.                 case 2:
  200.                 {
  201.                     _loc_2 = 0;
  202.                     while (_loc_2 < $sampleCount)
  203.                     {
  204.                         // label
  205.                         _loc_3 = param1[_loc_2];
  206.                         if (_loc_3.l < -1)
  207.                         {
  208.                             writeShort(-32767);
  209.                         }
  210.                         else if (_loc_3.l > 1)
  211.                         {
  212.                             writeShort(32767);
  213.                         }
  214.                         else
  215.                         {
  216.                             writeShort(_loc_3.l * 32767);
  217.                         }// end else if
  218.                         if (_loc_3.r < -1)
  219.                         {
  220.                             writeShort(-32767);
  221.                         }
  222.                         else if (_loc_3.r > 1)
  223.                         {
  224.                             writeShort(32767);
  225.                         }
  226.                         else
  227.                         {
  228.                             writeShort(_loc_3.r * 32767);
  229.                         }// end else if
  230.                         _loc_3.l = 0;
  231.                         _loc_3.r = 0;
  232.                         _loc_2++;
  233.                     }// end while
  234.                     break;
  235.                 }// end case
  236.                 default:
  237.                 {
  238.                     break;
  239.                 }// end default
  240.             }// end switch
  241.             SoundFactory.generate(this, channels, bits, rate, onNewBufferCreated);
  242.             length = 0;
  243.             return;
  244.         }// end function
  245.         public function get sampleCount() : uint
  246.         {
  247.             return $sampleCount;
  248.         }// end function
  249.         private function onNewBufferCreated(param1:Sound) : void
  250.         {
  251.             if (this.buffer == null)
  252.             {
  253.                 this.buffer = param1;
  254.             }
  255.             else
  256.             {
  257.                 new Error("PROBLEM");
  258.             }// end else if
  259.             return;
  260.         }// end function
  261.         public function get positionMillis() : Number
  262.         {
  263.             if (bufferChannel == null)
  264.             {
  265.                 return 0;
  266.             }// end if
  267.             return bufferChannel.position;
  268.         }// end function
  269.         public function get byteCount() : uint
  270.         {
  271.             return $byteCount;
  272.         }// end function
  273.         public function get lengthMillis() : Number
  274.         {
  275.             return 2048 * multiple / 44.1;
  276.         }// end function
  277.     }
  278. }
复制代码

[ 本帖最后由 龙城flash 于 2008-9-24 17:12 编辑 ]

TOP

开源代码:
AudioBuffer.as


  1. package de.popforge.audio.output
  2. {
  3. import flash.events.Event;
  4. import flash.media.Sound;
  5. import flash.media.SoundChannel;
  6. import flash.utils.ByteArray;
  7. import flash.utils.Endian;
  8. /**
  9.   * The class AudioBuffer creates an endless AudioStream
  10.   * as long as the buffer is updated with new samples
  11.   *
  12.   * @author Andre Michelle
  13.   */
  14. public class AudioBuffer
  15. {
  16.   /**
  17.    * The internal minimal sound buffer length in samples(PC)
  18.    */
  19.   static public const UNIT_SAMPLES_NUM: uint = 2048;
  20.   
  21.   /**
  22.    * Stores a delegate function called, when the AudioBuffer is inited.
  23.    */
  24.   public var onInit: Function;
  25.   /**
  26.    * Stores a delegate function called, when the AudioBuffer has complete its cycle.
  27.    */
  28.   public var onComplete: Function;
  29.   /**
  30.    * Stores a delegate function called, when the AudioBuffer is started.
  31.    */
  32.   public var onStart: Function;
  33.   /**
  34.    * Stores a delegate function called, when the AudioBuffer is stopped.
  35.    */
  36.   public var onStop: Function;
  37.   
  38.   private var multiple: uint;
  39.   private var channels: uint;
  40.   private var bits: uint;
  41.   private var rate: uint;
  42.   
  43.   private var sync: Sound;
  44.   private var syncChannel: SoundChannel;
  45.   private var sound: Sound;
  46.   private var soundChannel: SoundChannel;
  47.   
  48.   private var _numBytes: uint;
  49.   private var _numSamples: uint;
  50.   private var bytes: ByteArray;
  51.   private var samples: Array;
  52.   private var firstrun: Boolean;
  53.   private var playing: Boolean;
  54.   
  55.   private var $isInit: Boolean;
  56.   
  57.   /**
  58.    * Creates an AudioBuffer instance.
  59.    *
  60.    * @param multiple Defines the buffer length (4times recommended)
  61.    * @param channels Mono(1) or Stereo(2)
  62.    * @param bits 8bit(8) or 16bit(16)
  63.    * @param rate SamplingRate 5512Hz, 11025Hz, 22050Hz, 44100Hz
  64.    */
  65.   public function AudioBuffer( multiple: uint, channels: uint, bits: uint, rate: uint )
  66.   {
  67.    Audio.checkAll( channels, bits, rate );
  68.    
  69.    this.multiple = multiple;
  70.    this.channels = channels;
  71.    this.bits = bits;
  72.    this.rate = rate;
  73.    
  74.    firstrun = true;
  75.    
  76.    init();
  77.   }
  78.   /**
  79.    * Updates the AudioBuffer samples for the next playback cycle
  80.    * Must be called after the new samples are computed
  81.    */
  82.   public function update(): ByteArray
  83.   {
  84.    bytes.length = 0;
  85.    
  86.    var i: int;
  87.    var s: Sample;
  88.    var l: Number;
  89.    var r: Number;
复制代码

代码太长了,不全发了。
希望翻译一下开源代码的相关注释。和开源代码的函数(方法)作用或功能。

这两个 Sample 类 全部翻译的最少加 20 两。


[ 本帖最后由 龙城flash 于 2008-9-24 17:16 编辑 ]

TOP

刚才看了会儿,我想我明白点popforge类库的思路了。变速主要还是集中在SoundFactory,这老外的思路很奇特啊,第一次看到有人这么搞法。首先先import一个清白的swf(用了Embed,跟flash的导入一样),转化成bytearray,然后朝里面写入声音编码(PCM),swf二进制格式也是开放的,它这么写入之后就形成了一个新的带声音元件的swf(完全以二进制存在与内存)。最后用loadBytes方法导入这个swf,把声音元件实例化一个Sound。如果要变速,改变samplerate。
现在关键是samples从哪来的问题。唉,没必要样样都得用AS解决。
1

评分人数

  • 龙城flash

龙城flash 赐本贴 银子 + 5  诏曰: 你的发言很有用。

TOP

回复 马扎 的帖子

使用 byteArray 类可以进行深复制,这样改变复制后的声音,原始声音不会发生改变。

TOP

回复 7# 的帖子

因为我听他改变后的声音,原来发的音没没有改变,只是改变了速度,我想用的就是用AS实现,这样就可以控制大量从外部加载的声音了。

TOP

呵呵,我已经分别发了两封邮件给那两个作者了,如果运气好的话明天就是答案。大家猜来猜去的多费劲

TOP

额,,,顶下,,,想知道结果

TOP

回复 10# 的帖子

期待你翻译成 中文说明。

悬赏继续进行。有好的发言继续加分。

[ 本帖最后由 龙城flash 于 2008-9-24 21:12 编辑 ]

TOP

刚才试验一下,可以随意调整帧频的,这样就好办了吧?

frameRate 属性   

frameRate:Number  [read-write]

语言版本 :  ActionScript 3.0
Player 版本 :  Flash Player 9


获取并设置舞台的帧频。 帧频是指每秒显示的帧数。 默认情况下,频率设置为第一个加载的 SWF 文件的帧频。 帧频的有效范围为每秒 0.01 到 1000 个帧。

TOP

如果可以随意调整帧频,那你要变快,就只要把帧频调整一下就可以了

TOP

。。。。楼上,实践第一,好吧。
开源项目:http://code.google.com/p/ghostcat
QQ群:76198937

TOP

返回列表