Browse
 
Tools
Rss Categories

audioStreamer.h

Reference Number: AA-01511 Views: 7131 0 Rating/ Voters

C++ Code

  1. #include "HeaderClasses.h"
  2. #ifndef AUDIO_STREAMER_H
  3. #define AUDIO_STREAMER_H
  4. typedef bool (*AudioStreamCB)(char* audio_chunk, int chunk_size, void* user_data);
  5. /**
  6. class AudioStreamer
  7. Mimics live audio being streamed.
  8. It reads audio a bit at a time from a file,
  9. periodically calling a user provided callback
  10. function to transmit the audio.
  11. It stops transmitting audio when the user
  12. callback function returns false.
  13. If it reaches the end of file before the callback
  14. tells it to stop, then it just sends silence.
  15. The audio is assumed to be a headerless u-Law
  16. audio file at 8Khz
  17. **/
  18. class AudioStreamer: Demo::Thread
  19. {
  20. public:
  21. AudioStreamer(const char* filename);
  22. void StartStream(AudioStreamCB _cb, void* _user_data);
  23. void StopStream();
  24. ~AudioStreamer();
  25. private:
  26. char* audio_buffer;
  27. char* end_buffer;
  28. int audio_buffer_size;
  29. int increment_ms;
  30. AudioStreamCB cb;
  31. void* user_data;
  32. virtual void ThreadAction();
  33. };

  34. #endif//AUDIO_STREAMER_H