Guest User

SFML Audio Glitch

a guest
Jul 31st, 2011
141
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. Main.h:
  3.  
  4. #pragma once
  5.  
  6. #include <Windows.h>
  7. #include <WindowsX.h>
  8.  
  9. #include <iostream>
  10. #include <vector>
  11. #include <list>
  12.  
  13. #include <ctime>
  14. #include <cmath>
  15.  
  16. #include <d3d9.h>
  17. #include <d3dx9.h>
  18.  
  19. #include <SFML/Audio.hpp>
  20.  
  21. #pragma comment (lib, "d3d9.lib")
  22. #pragma comment (lib, "d3dx9.lib")
  23.  
  24. using namespace std;
  25.  
  26. #define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
  27.  
  28.  
  29.  
  30.  
  31. Main.cpp:
  32.  
  33. #include "Main.h"
  34.  
  35. sf::SoundBuffer Buffer;
  36. sf::Sound Sound(Buffer);
  37.  
  38. void LoadSoundSFML();
  39. void PlaySoundSFML();
  40.  
  41. bool Edown;
  42.  
  43. int main()
  44. {
  45.     LoadSoundSFML();
  46.  
  47.     // Quit on escape key press
  48.     while(KEY_DOWN(VK_ESCAPE) == false)
  49.     {
  50.         // E key
  51.         if(KEY_DOWN(0x45) && Edown)
  52.         {
  53.             // Do nothing
  54.         }
  55.         else if(KEY_DOWN(0x45))
  56.         {
  57.             cout << "Playing sound\n";
  58.  
  59.             PlaySoundSFML();
  60.  
  61.             Edown = true;
  62.         }
  63.         else
  64.             Edown = false;
  65.     }
  66.  
  67.     return 0;
  68. }
  69.  
  70. void LoadSoundSFML()
  71. {
  72.     // Load a sound buffer from a wav file
  73.     if (!Buffer.LoadFromFile("Test3.wav"))
  74.         return;
  75. }
  76.  
  77. void PlaySoundSFML()
  78. {
  79.     // Play sound instance
  80.     Sound.SetVolume(100);
  81.     Sound.Play();
  82. }
RAW Paste Data