Guest User

Untitled

a guest
Mar 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #include <chrono>
  2. #include <iostream>
  3. #include <thread>
  4. #include <SDL2/SDL.h>
  5.  
  6. void callback( void *, Uint8 * stream, int len )
  7. {
  8. memset( stream, 0, len );
  9. }
  10.  
  11. int main()
  12. {
  13. if( SDL_Init( SDL_INIT_AUDIO ) != 0 )
  14. {
  15. std::cerr << "SDL_Init(): " << SDL_GetError() << std::endl;
  16. SDL_ClearError();
  17. return 1;
  18. }
  19.  
  20. SDL_AudioSpec specs = {};
  21. specs.freq = 48000;
  22. specs.format = AUDIO_S32;
  23. specs.channels = 2;
  24. specs.samples = 4096;
  25. specs.callback = callback;
  26.  
  27. constexpr int PLAYBACK_DEV = 0;
  28.  
  29. const int audio_dev_id = SDL_OpenAudioDevice( nullptr, PLAYBACK_DEV, &specs,
  30. nullptr, SDL_AUDIO_ALLOW_CHANNELS_CHANGE );
  31.  
  32. if( audio_dev_id == 0 )
  33. {
  34. std::cerr << "Error opening audio device: " << SDL_GetError() << std::endl;
  35. return 1;
  36. }
  37.  
  38. while( true )
  39. {
  40. std::this_thread::sleep_for( std::chrono::seconds( 5 ) );
  41. }
  42. }
Add Comment
Please, Sign In to add comment