Guest User

audio stream

a guest
Sep 24th, 2012
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.27 KB | None | 0 0
  1. #include <m_std\\iostr.h> //iostr is the standard IO lib for music studios C++ lib
  2. #include <m_std\\report.h> //report is the standard report for music studios C++ lib
  3. #include <m_std\\thread.h> //thread is the standard thread for music studios C++ lib
  4.  
  5. int main()
  6. {
  7.     std::INSTREAM* istream = (std::INSTREAM*)new std::STREAM.create("IN_DEVICE"); // creates an input stream
  8.     std::OUTSTREAM* ostream = (std::OUTSTREAM*)new std::STREAM.create("OUT_DEVICE"); // creates an output stream
  9.  
  10.     std::AUDIOSTREAM* astream = (std::AUDIOSTREAM*)new std::STREAM.create("AUDIO_DEVICE", L"ALL"); // creates an audio stream
  11.  
  12.     if (astream->aSize() == 0) // if the audio stream has no devices
  13.     {
  14.         std::REPORTER.set("Audio Report", "Could not find any audio streams to record from.");
  15.         std::STREAM.forceClose(L"ALL"); // forcing all streams to close
  16.         return 0;
  17.     }
  18.  
  19.     if (astream->streams.isNull(istream) || astream->streams.isNull(ostream)) // tries to attach both the input and output streams, but as well return if they were null
  20.     {
  21.         std::REPORTER.set("Audio Report", "Could not create an input or output for the audio stream.");
  22.         std::STREAM.forceClose(L"ALL"); // forcing all streams to close
  23.         return 0;
  24.     }
  25.  
  26.     while (astream->recordAudio("STATUS") == "NO_RECORD") // while the audio stream is not recording
  27.     {
  28.         astream->waitForInput(std::M_THREAD.getSleep()); // sleep the time necessary for lowest cpu usage as possible
  29.     }
  30.  
  31.     astream->attachDevice("STD_DEVICE", "INPUT"); // attach the input device for recoding
  32.  
  33.     while (astream->recordAudio("STATUS") == "AUDIO_IN") // while the audio stream is recording
  34.     {
  35.         astream->create(); // create a buffer and attach recorded sound to the buffer created. if a buffer exists it will add to that
  36.     }
  37.  
  38.     astream->detachDevice("STD_DEVICE", "INPUT"); // detachs the input device again
  39.     astream->attachDevice("STD_DEVICE", "OUTPUT"); // attachs the output device
  40.  
  41.     std::MEDIASTREAM* mstream = (std::MEDIASTREAM*)new std::STREAM.create("MEDIA"); // creates a media stream
  42.     mstream->setMediaType(L"P_AUDIO", L"M_AUDIO", L"N_MP3"); // sets all audio media types, except for mp4 though it's possible using the MP4STREAM instead
  43.  
  44.     astream->attachOutput(mstream->getStream()); // attachs the media stream to the audio stream
  45.  
  46.     while (mstream->isPlay()) // while the media stream is playing (it's now associated with the buffer from the audio stream
  47.     {
  48.         if (mstream.reachPoint != NULL) // if the reach point is not null
  49.             if (mstream.reachPoint == std::MPOINT.end) // if the reach point is the end of the media
  50.                 if (mstream.replay) // if the media should replay
  51.                     mstream.position = 0; // set the media position to 0 (start)
  52.  
  53.         astream->create(); // create a buffer for dislaying (sound in this case), if the buffer exists it will add sound to it
  54.     }
  55.  
  56.     astream->detachDevice("STD_DEVICE", "OUTPUT"); // detach the output device
  57.     delete mstream; // deletes the media stream since it's not bound to the std streams (the reason is that the media stream has to be attached to another stream
  58.  
  59.     std::STREAM.forceClose(L"ALL"); // forcing all streams to close
  60.  
  61.     if (std::REPORT.get() != NULL) // checks if the report has any data ex. invalid devices etc.
  62.         return std::REPORT.important("ERROR_CODE"); // returns the most important error code
  63.  
  64.     return 0;// success
  65. }
Add Comment
Please, Sign In to add comment