Advertisement
Eeedi

Techniki multimedialne lab5

May 15th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.31 KB | None | 0 0
  1. // This example will show how to use sound effects such as echo, reverb and distortion.
  2. // irrKlang supports the effects Chorus, Compressor, Distortion, Echo, Flanger
  3. // Gargle, 3DL2Reverb, ParamEq and WavesReverb.
  4.  
  5. // Lets start: include the irrKlang headers and other input/output stuff
  6. // needed to print and get user input from the console. And as exlained
  7. // in the first tutorial, we use the namespace irr and audio and
  8. // link to the irrKlang.dll file.
  9. #if defined(WIN32)
  10.     #include <conio.h>
  11. #else
  12.     #include "../common/conio.h"
  13. #endif
  14.  
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <irrKlang.h>
  18. using namespace irrklang;
  19.  
  20. #pragma comment(lib, "irrKlang.lib") // link with irrKlang.dll
  21.  
  22.  
  23. // Now let's start with the irrKlang 3D sound engine example 05,
  24. // demonstrating sound effects. Simply startup the engine using
  25. // using createIrrKlangDevice() with default options/parameters.
  26. int main(int argc, const char** argv)
  27. {
  28.  
  29.     ik_f32 a=8, b=-9, c=7;
  30.  
  31.     // start the sound engine with default parameters
  32.     ISoundEngine* engine = createIrrKlangDevice();
  33.  
  34.     if (!engine)
  35.         return 0; // error starting up the engine
  36.  
  37.     // we play a .xm file as music here. Note that the last parameter
  38.     // named 'enableSoundEffects' has been set to 'true' here. If this
  39.     // is not done, sound effects cannot be used with this sound.
  40.     // After this, we print some help text and start a loop which reads
  41.     // user keyboard input.
  42.    
  43.     const char* filename = "../../media/MF-W-90.XM";
  44.  
  45.     #ifdef __BIG_ENDIAN__
  46.         filename = "../../media/ophelia.mp3"; // no xm playback on power pcs currently
  47.     #endif
  48.    
  49.     ISound* music = engine->play2D(filename,
  50.         true, false, true, ESM_AUTO_DETECT, true);
  51.  
  52.     // Print some help text and start the display loop
  53.  
  54.     printf("\nSound effects example. Keys:\n");
  55.     printf("\nESCAPE: quit\n");
  56.     printf("w: enable/disable waves reverb\n");
  57.     printf("d: enable/disable distortion\n");
  58.     printf("e: enable/disable echo\n");
  59.     printf("f: enable/disable chorus\n");
  60.     printf("r: enable/disable flanger\n");
  61.     printf("t: enable/disable gargle\n");
  62.     printf("y: enable/disable compressor\n");
  63.     printf("a: disable all effects\n");
  64.  
  65.     while(true) // endless loop until user exits
  66.     {
  67.         int key = getch();
  68.  
  69.         if (key == 27)
  70.             break; // user pressed ESCAPE key
  71.         else
  72.         {
  73.             // user maybe pressed an effects key,
  74.             // now enable or disable a sound effect.
  75.  
  76.             // We get a pointer to the ISoundEffectControl interface,
  77.             // but this only exists if the sound driver supports sound effects
  78.             // and if the sound was started setting the 'enableSoundeffects' flag
  79.             // to 'true' as we did above. This pointer is only valid as long as
  80.             // we don't call music->drop() and delete the music with this.
  81.  
  82.             ISoundEffectControl* fx = 0;
  83.             if (music)
  84.                 fx = music->getSoundEffectControl();
  85.  
  86.             if (!fx)
  87.             {
  88.                 // some sound devices do not support sound effects.
  89.                 printf("This device or sound does not support sound effects.\n");
  90.                 continue;
  91.             }  
  92.  
  93.             // here we disable or enable the sound effects of the music depending
  94.             // on what key the user pressed. Note that every enableXXXSoundEffect()
  95.             // method also accepts a lot of parameters, so it is easily possible
  96.             // to influence the details of the effect. If the sound effect is
  97.             // already active, it is also possible to simply call the
  98.             // enableXXXSoundEffect() method again to just change the effect parameters,
  99.             // although we aren't doing this here.
  100.  
  101.             if (key < 'a') // make key lower
  102.                 key += 'a' - 'A';
  103.  
  104.  
  105.  
  106.             switch(key)
  107.             {
  108.             case 'd':
  109.                 if (fx->isDistortionSoundEffectEnabled())
  110.                     fx->disableDistortionSoundEffect();
  111.                 else
  112.                     fx->enableDistortionSoundEffect();
  113.                 break;
  114.  
  115.             case 'e':
  116.                 if (fx->isEchoSoundEffectEnabled())
  117.                     fx->disableEchoSoundEffect();
  118.                 else
  119.                     fx->enableEchoSoundEffect();
  120.                 break;
  121.  
  122.             case 'w':
  123.                 if (fx->isWavesReverbSoundEffectEnabled())
  124.                     fx->disableWavesReverbSoundEffect();
  125.                 else
  126.                     fx->enableWavesReverbSoundEffect();
  127.                 break;
  128.             case 'f':
  129.                 if(fx->isChorusSoundEffectEnabled())
  130.                     fx->disableChorusSoundEffect();
  131.                 else
  132.                     fx->enableChorusSoundEffect();
  133.                 break;
  134.             case 'r':
  135.                 if(fx->isFlangerSoundEffectEnabled())
  136.                     fx->disableFlangerSoundEffect();
  137.                 else
  138.                     fx->enableFlangerSoundEffect();
  139.                 break;
  140.             case 't':
  141.                 if(fx->isGargleSoundEffectEnabled())
  142.                     fx->disableGargleSoundEffect();
  143.                 else
  144.                     fx->enableGargleSoundEffect();
  145.                 break;
  146.             case 'y':
  147.                 if(fx->isCompressorSoundEffectEnabled())
  148.                     fx->disableCompressorSoundEffect();
  149.                 else
  150.                     fx->enableCompressorSoundEffect();
  151.                 break;
  152.             case 'o':
  153.                 a+=1;
  154.                 fx->enableParamEqSoundEffect(300,36,a);
  155.                 break;
  156.             case 'l':
  157.                 a-=1;
  158.                 fx->enableParamEqSoundEffect(300,36,a);
  159.                 break;
  160.             case 'i':
  161.                 b+=1;
  162.                 fx->enableParamEqSoundEffect(1046.5,24,b);
  163.                 break;
  164.             case 'k':
  165.                 b-=1;
  166.                 fx->enableParamEqSoundEffect(1046.5,24,b);
  167.                 break;
  168.             case 'u':
  169.                 c+=1;
  170.                 fx->enableParamEqSoundEffect(8372,36,c);
  171.                 break;
  172.             case 'j':
  173.                 c-=1;
  174.                 fx->enableParamEqSoundEffect(8372,36,c);
  175.                 break;
  176.             case 'a':
  177.                 fx->disableAllEffects();
  178.                 break;
  179.             }
  180.         }          
  181.     }
  182.     // don't forget to release the resources
  183.  
  184.     if (music)
  185.         music->drop(); // release music stream.
  186.  
  187.     engine->drop(); // delete Engine
  188.  
  189.     return 0;
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement