Prueba de Pixel Bender + ComputeSpectrum

Prueba de Pixel Bender + ComputeSpectrum

Etiquetas: computeSpectrum ShaderFilter Shader SoundMixer SoundChannel ByteArray

Imagen en reemplazo de flash
Prueba de computeSpectrum + un filtro de Pixel Bender. En el ejemplo se muestra como cargar un filtro de pixel Bender, y aplicarlos en Flash variando sus parámetros en función de un sonido.

  1. package {
  2.  
  3.     import flash.display.*
  4.     import flash.events.*;
  5.     import flash.media.*;
  6. 	import flash.filters.*;
  7. 	import flash.net.*;
  8. 	import flash.utils.ByteArray;
  9.  
  10.     public class Main extends Sprite {
  11.  
  12.         private var shader:Shader;
  13. 		private var filtro:ShaderFilter;
  14. 		var url:String = "sonido.mp3";
  15. 		var canal:SoundChannel;
  16. 		var sonido:Sound;
  17. 		var fourierTransform:Boolean = false;
  18. 		var arrayMixer:ByteArray = new ByteArray();
  19. 		var volumenes:Array = new Array();
  20. 		var loader:URLLoader
  21.  
  22.         public function Main() {
  23. 			cargarFiltro();
  24.  
  25.         }
  26.  
  27.         private function cargarFiltro():void{
  28. 			loader = new URLLoader();
  29. 			loader.dataFormat = URLLoaderDataFormat.BINARY;
  30. 			loader.addEventListener(Event.COMPLETE,filtroCargado);
  31. 			loader.load(new URLRequest("pixelate.pbj"));
  32. 		}
  33.  
  34. 		private function filtroCargado(e:Event):void{
  35. 			shader = new Shader(e.target.data);
  36. 			filtro = new ShaderFilter(shader);
  37. 			filters = [filtro];
  38. 			cargarSonido();
  39. 		}
  40. 		function cargarSonido():void {
  41. 			SoundMixer.stopAll();
  42. 			sonido = new Sound();
  43. 			var request:URLRequest = new URLRequest(url);
  44. 			sonido.addEventListener(Event.COMPLETE, sonidoCargado);
  45. 			sonido.load(request);
  46. 		}
  47.  
  48. 		function sonidoCargado(event:Event):void{
  49. 			canal = sonido.play(0,1000);
  50. 			addEventListener(Event.ENTER_FRAME,mover)
  51. 		}
  52.  
  53. 		function mover(e:Event):void {
  54. 			SoundMixer.computeSpectrum(arrayMixer, true);
  55. 			var c = 1;
  56. 			for(var i = 0; i < arrayMixer.length; i++){
  57. 				c += arrayMixer[i];
  58. 			}
  59. 			shader = new Shader(loader.data);
  60. 			shader.data.dimension.value = [c/5000];
  61. 			filtro = new ShaderFilter(shader);
  62. 			filters = [filtro];
  63. 		}
  64.  
  65.     }
  66. }

Descargar archivos

Comentarios

    No hay comentarios

Dejar un comentario
Tu nombre (obligatorio):

E-mail (obligatorio, no se mostrará):

Web:

Comentario: