1+ #ifdef _WIN32
12
23#include " ofMediaFoundationSoundPlayer.h"
34#include " ofLog.h"
@@ -168,7 +169,7 @@ void ofMediaFoundationSoundPlayer::sCloseAudioSystems() {
168169 sNumInstances --;
169170 if (sNumInstances <= 0 ) {
170171 ofLogVerbose (" ofMediaFoundationSoundPlayer" ) << " closing XAudio2." ;
171- sCloseXAudio2 ();
172+ sCloseXAudio2 ();
172173 }
173174 ofMediaFoundationUtils::CloseMediaFoundation ();
174175 if (sNumInstances < 0 ) {
@@ -189,7 +190,7 @@ ofMediaFoundationSoundPlayer::~ofMediaFoundationSoundPlayer() {
189190// --------------------
190191bool ofMediaFoundationSoundPlayer::load (const of::filesystem::path & fileName, bool stream) {
191192 unload ();
192-
193+
193194 auto filePath = fileName;
194195 std::string fileStr = ofPathToString (fileName);
195196 bool bStream = false ;
@@ -223,7 +224,7 @@ bool ofMediaFoundationSoundPlayer::load(const of::filesystem::path & fileName, b
223224
224225
225226 LPCWSTR path = filePath.c_str ();
226-
227+
227228
228229 hr = MFCreateSourceReaderFromURL (
229230 path,
@@ -255,14 +256,14 @@ bool ofMediaFoundationSoundPlayer::load(const of::filesystem::path & fileName, b
255256 hr = mSrcReader ->GetNativeMediaType (MF_SOURCE_READER_FIRST_AUDIO_STREAM, 0 , &nativeType);
256257
257258 auto nativeTypePtr = std::unique_ptr<IMFMediaType, MyComDeleterFunctor>(nativeType);
258- // get a wave format
259+ // get a wave format
259260 hr = MFCreateWaveFormatExFromMFMediaType (nativeType, &nativeFormat, &formatSize);
260-
261+
261262 mNumChannels = nativeFormat->nChannels ;
262263 mSampleRate = nativeFormat->nSamplesPerSec ;
263264
264265 CoTaskMemFree (nativeFormat);
265-
266+
266267
267268 ComPtr<IMFMediaType> mediaType;
268269 hr = MFCreateMediaType (mediaType.GetAddressOf ());
@@ -335,19 +336,19 @@ bool ofMediaFoundationSoundPlayer::load(const of::filesystem::path & fileName, b
335336 }
336337
337338 ofLogVerbose (" ofMediaFoundationSoundPlayer::load" ) << " made it all the way to the end." ;
338-
339+
339340 if (!mBStreaming ) {
340341 mSrcReader .Reset ();
341342 mSrcReader = nullptr ;
342343 }
343344
344345 {
345346
346- // create stream context for listening to voice
347+ // create stream context for listening to voice
347348 mVoiceContext = std::make_shared<StreamingVoiceContext>();
348349 // Create the source voice
349350 IXAudio2SourceVoice* pSourceVoice = nullptr ;
350- // setting max freq ratio to 3, though it may need to be higher to play at a
351+ // setting max freq ratio to 3, though it may need to be higher to play at a
351352 // faster pitch
352353 if (mBStreaming ) {
353354 hr = sXAudio2 ->CreateSourceVoice (
@@ -430,7 +431,7 @@ void ofMediaFoundationSoundPlayer::unload() {
430431 mTotalNumFrames = 0 ;
431432 mNumSamplesAlreadyPlayed = 0 ;
432433 mBRequestNewReaderSample = false ;
433-
434+
434435 LeaveCriticalSection (&m_critSec);
435436};
436437
@@ -467,7 +468,7 @@ void ofMediaFoundationSoundPlayer::update(ofEventArgs& args) {
467468 } else {
468469 bRequestStop = true ;
469470 // we need to request stop outside of the scope of the lock
470- // since stop() also locks to set vars
471+ // since stop() also locks to set vars
471472 }
472473 }
473474 }
@@ -497,7 +498,7 @@ void ofMediaFoundationSoundPlayer::update(ofEventArgs& args) {
497498 if (!xstate.BuffersQueued && mExtraVoices .size () < 1 ) {
498499 // we have reached the end //
499500 if (mBLoop ) {
500- // set isPlaying to false, so that it will create a new instance
501+ // set isPlaying to false, so that it will create a new instance
501502 // for mVoice and not an Extra Voice
502503 mPosPct = 0 .0f ;
503504 mBIsPlaying = false ;
@@ -530,7 +531,7 @@ void ofMediaFoundationSoundPlayer::play() {
530531 return ;
531532 }
532533
533- // don't want a ton of loops going on here
534+ // don't want a ton of loops going on here
534535 if (mBLoop ) {
535536 stop ();
536537 }
@@ -539,7 +540,7 @@ void ofMediaFoundationSoundPlayer::play() {
539540 }
540541
541542 if (mBStreaming ) {
542- // just in case, multiplay is not supported for streams
543+ // just in case, multiplay is not supported for streams
543544 _clearExtraVoices ();
544545 }
545546
@@ -583,7 +584,7 @@ void ofMediaFoundationSoundPlayer::play() {
583584 XAUDIO2_BUFFER buffer = {};
584585 buffer.pAudioData = mBuffer .data ();
585586 // tell the source voice not to expect any data after this buffer
586- buffer.Flags = XAUDIO2_END_OF_STREAM;
587+ buffer.Flags = XAUDIO2_END_OF_STREAM;
587588 buffer.AudioBytes = mBuffer .size ();
588589
589590 hr = pSourceVoice->SubmitSourceBuffer (&buffer);
@@ -605,7 +606,7 @@ void ofMediaFoundationSoundPlayer::play() {
605606 buffer.AudioBytes = mBuffer .size ();
606607
607608 mVoice ->SubmitSourceBuffer (&buffer);
608-
609+
609610 }
610611
611612 mVoice ->SetVolume (mVolume );
@@ -711,7 +712,7 @@ void ofMediaFoundationSoundPlayer::setPaused(bool bP) {
711712// --------------------
712713void ofMediaFoundationSoundPlayer::setLoop (bool bLp) {
713714 if (bLp) {
714- // we don't want a lot of looping iterations
715+ // we don't want a lot of looping iterations
715716 _clearExtraVoices ();
716717 }
717718 mBLoop = bLp;
@@ -740,7 +741,7 @@ void ofMediaFoundationSoundPlayer::setPosition(float pct) {
740741 ofLogWarning (" ofMediaFoundationSoundPlayer::setPosition" ) << " unable to seek." ;
741742 return ;
742743 }
743-
744+
744745 // ok we need to kill buffers and resubmit a buffer
745746 if (mVoice ) {
746747 std::ignore = mVoice ->Stop ();
@@ -785,7 +786,7 @@ void ofMediaFoundationSoundPlayer::setPositionMS(int ms) {
785786};
786787
787788// --------------------
788- float ofMediaFoundationSoundPlayer::getPosition () const {
789+ float ofMediaFoundationSoundPlayer::getPosition () const {
789790 return mPosPct ;
790791};
791792
@@ -880,7 +881,7 @@ void ofMediaFoundationSoundPlayer::OnSourceReaderEvent(HRESULT hrStatus, DWORD d
880881 }
881882
882883 hr = mediaBuffer->Unlock ();
883-
884+
884885 if (mVoice && mVoiceContext ) {
885886 XAUDIO2_VOICE_STATE state;
886887
@@ -909,7 +910,7 @@ void ofMediaFoundationSoundPlayer::OnSourceReaderEvent(HRESULT hrStatus, DWORD d
909910 std::unique_lock<std::mutex> lk (mSrcReaderMutex );
910911 mBRequestNewReaderSample = true ;
911912 }
912-
913+
913914 }
914915}
915916
@@ -953,7 +954,7 @@ void ofMediaFoundationSoundPlayer::_setPan(IXAudio2SourceVoice* avoice, float ap
953954 float outputMatrix[8 ];
954955 for (int i = 0 ; i < 8 ; i++) outputMatrix[i] = 0 ;
955956
956- // pan of -1.0 indicates all left speaker,
957+ // pan of -1.0 indicates all left speaker,
957958// 1.0 is all right speaker, 0.0 is split between left and right
958959 float left = 0 .5f - apan / 2 ;
959960 float right = 0 .5f + apan / 2 ;
@@ -990,7 +991,7 @@ void ofMediaFoundationSoundPlayer::_setPan(IXAudio2SourceVoice* avoice, float ap
990991
991992 // Assuming pVoice sends to pMasteringVoice
992993
993- // TODO: Cache this
994+ // TODO: Cache this
994995 XAUDIO2_VOICE_DETAILS MasterVoiceDetails;
995996 sXAudioMasteringVoice ->GetVoiceDetails (&MasterVoiceDetails);
996997
@@ -1019,7 +1020,7 @@ bool ofMediaFoundationSoundPlayer::_readToBuffer(IMFSourceReader* areader) {
10191020 HRESULT hr = areader->ReadSample (
10201021 MF_SOURCE_READER_FIRST_AUDIO_STREAM,
10211022 0 , // Flags.
1022- &streamIndex, // Receives the actual stream index.
1023+ &streamIndex, // Receives the actual stream index.
10231024 &flags, // Receives status flags.
10241025 &llAudioTimeStamp, // Receives the time stamp.
10251026 &audioSample // Receives the sample or NULL.
@@ -1049,14 +1050,14 @@ bool ofMediaFoundationSoundPlayer::_readToBuffer(IMFSourceReader* areader) {
10491050 if (hr != S_OK) {
10501051 continue ;
10511052 }
1052-
1053+
10531054 size_t numFramesRead = uint64_t (sampleBufferLength) / (bytes64 * numChannels64);
10541055 ofLogVerbose (" ofMediaFoundationSoundPlayer::_readToBuffer" ) << " sampleBufferLength : " << sampleBufferLength << " num frames: " << numFramesRead << std::endl;
10551056 totalFrames += numFramesRead;
10561057 std::vector<BYTE> tempBuffer;
10571058 tempBuffer.resize (sampleBufferLength, 0 );
10581059 memcpy_s (tempBuffer.data (), sampleBufferLength, audioData, sampleBufferLength);
1059- // add into the main buffer?
1060+ // add into the main buffer?
10601061 mBuffer .insert (mBuffer .end (), tempBuffer.begin (), tempBuffer.end ());
10611062
10621063 hr = mediaBuffer->Unlock ();
@@ -1073,3 +1074,5 @@ bool ofMediaFoundationSoundPlayer::_readToBuffer(IMFSourceReader* areader) {
10731074 ofLogVerbose (" ofMediaFoundationSoundPlayer::_readToBuffer" ) << " Total frames read: " << (totalFrames) << " mTotalNumFrames: " << mTotalNumFrames << " dur millis: " << durMillis << " dur seconds: " << durSeconds << std::endl;
10741075 return mBuffer .size () > 0 ;
10751076}
1077+
1078+ #endif
0 commit comments