Advertisement
Guest User

Untitled

a guest
Feb 10th, 2012
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.06 KB | None | 0 0
  1. /*
  2.  *  Version: MPL 1.1
  3.  *
  4.  *  The contents of this file are subject to the Mozilla Public License Version
  5.  *  1.1 (the "License"); you may not use this file except in compliance with
  6.  *  the License. You may obtain a copy of the License at
  7.  *  http://www.mozilla.org/MPL/
  8.  *
  9.  *  Software distributed under the License is distributed on an "AS IS" basis,
  10.  *  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  *  for the specific language governing rights and limitations under the
  12.  *  License.
  13.  *
  14.  *  The Original Code is the SA:MP FFT Particle Visualizer
  15.  *
  16.  *  The Initial Developer of the Original Code is Scott Reed - h02@h02.org
  17.  *  Portions created by the Initial Developer are Copyright (C) 2012
  18.  *  the Initial Developer. All Rights Reserved.
  19.  */
  20.  
  21. /* IMPORTANT NOTE: Use PlayAudioStreamForPlayer to send audio to clients, this script will only receive the audio stream to the server */
  22.  
  23. #include <a_samp>
  24. #include <spectrum>
  25.  
  26. #define FTYPE_WHITE     0
  27. #define FTYPE_RED       1
  28. #define FTYPE_GREEN     2
  29. #define FTYPE_BLUE      3
  30.  
  31. #define FWHITE          19281
  32. #define FRED            19282
  33. #define FGREEN          19283
  34. #define FBLUE           19284
  35.  
  36. #define FWHITE_HUGE     19295
  37. #define FRED_HUGE       19296
  38. #define FGREEN_HUGE     19297
  39. #define FBLUE_HUGE      19298
  40.  
  41. #define BARS 128
  42.  
  43. new objects[BARS];
  44.  
  45. new Float:fftvalue[BARS];
  46.  
  47. new timer;
  48.  
  49. public OnFilterScriptInit()
  50. {
  51.     //initialize the output device, receive the stream
  52.     if(BASS_Init() && BASS_PlayStream("http://yp.shoutcast.com/sbin/tunein-station.pls?id=502985"))
  53.     {
  54.         printf("update");
  55.         timer = SetTimer("Update", 25, true); //40hz timer to fetch the fft data
  56.     }
  57.     else printf("Spectrum: Init error %d", BASS_ErrorGetCode());
  58. }
  59.  
  60. public OnFilterScriptExit()
  61. {
  62.     for(new x;x<MAX_PLAYERS;x++)
  63.     {
  64.         if(IsPlayerConnected(x)) StopAudioStreamForPlayer(x);
  65.     }
  66.     KillTimer(timer);
  67.     for(new x;x<sizeof(objects);x++) DestroyObject(objects[x]);
  68.     if(!BASS_Free()) printf("Spectrum: Free error %d", BASS_ErrorGetCode()); //frees all resources of the output device
  69. }
  70.  
  71. forward Update();
  72. public Update()
  73. {
  74.     new Float:fft[BARS];
  75.     if(BASS_ChannelGetData(fft, BASS_DATA_FFT256))
  76.     {
  77.         for(new x;x<BARS;x++)
  78.         {
  79.             if((fft[x]-fftvalue[x] > 0.1))
  80.             {
  81.                 if(!objects[x])
  82.                 {
  83.                     new left, right;
  84.                     if(BASS_ChannelGetLevel(left, right))
  85.                     {
  86.                         printf("Beat detected at %d - %f, %d %d", x, fft[x]-fftvalue[x], left, right);
  87.                        
  88.                         new object;
  89.                         if(x < 5) object = FTYPE_WHITE;
  90.                         else if(x >= 5 && x < 15) object = FTYPE_RED;
  91.                         else if(x >= 15 && x < 25) object = FTYPE_GREEN;
  92.                         else if(x >= 25) object = FTYPE_BLUE;
  93.  
  94.                         if(left > 80 || right > 80)
  95.                         {
  96.                             switch(object)
  97.                             {
  98.                                 case FTYPE_WHITE: object = FRED_HUGE;
  99.                                 case FTYPE_RED: object = FGREEN_HUGE;
  100.                                 case FTYPE_GREEN: object = FBLUE_HUGE;
  101.                                 case FTYPE_BLUE: object = FWHITE_HUGE;
  102.                             }
  103.                         }
  104.                         else
  105.                         {
  106.                             switch(object)
  107.                             {
  108.                                 case FTYPE_WHITE: object = FRED;
  109.                                 case FTYPE_RED: object = FGREEN;
  110.                                 case FTYPE_GREEN: object = FBLUE;
  111.                                 case FTYPE_BLUE: object = FWHITE;
  112.                             }
  113.                         }
  114.  
  115.                         objects[x] = CreateObject(object, 1479.0, -1641.0, 14.0, 0.0, 0.0, 0.0);
  116.                         switch(random(2))
  117.                         {
  118.                             case 0: MoveObject(objects[x], 1479.0+((random(1))+fft[x]*20), -1641.0+((random(1))+fft[x]*30), 14.0+(left*0.15), 20.0);
  119.                             default: MoveObject(objects[x], 1479.0-((random(1))+fft[x]*20), -1641.0-((random(1))+fft[x]*30), 14.0+(left*0.15), 20.0);
  120.                         }
  121.                     }
  122.                     else printf("Spectrum: ChannelGetLevel error %d", BASS_ErrorGetCode());
  123.                 }
  124.             }
  125.             fftvalue[x] = fft[x];
  126.         }
  127.     }
  128.     else printf("Spectrum: ChannelGetData error %d", BASS_ErrorGetCode());
  129. }
  130.  
  131. public OnObjectMoved(objectid)
  132. {
  133.     for(new x;x<sizeof(objects);x++)
  134.     {
  135.         if(objects[x] == objectid)
  136.         {
  137.             DestroyObject(objectid);
  138.             objects[x] = 0;
  139.             break;
  140.         }
  141.     }
  142.     return 1;
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement