/// @brief Constructor /// @param filename /// FFmpegSourceAudioProvider::FFmpegSourceAudioProvider(std::string filename) : AudioSource(NULL) , COMInited(false) { #ifdef WIN32 HRESULT res; res = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); if (SUCCEEDED(res)) COMInited = true; else if (res != RPC_E_CHANGED_MODE) throw AudioOpenError("COM initialization failure"); #endif // initialize ffmpegsource // FIXME: CPU detection? #if FFMS_VERSION >= ((2 << 24) | (14 << 16) | (0 << 8) | 0) FFMS_Init(0, 1); #else FFMS_Init(0); #endif ErrInfo.Buffer = FFMSErrMsg; ErrInfo.BufferSize = sizeof(FFMSErrMsg); ErrInfo.ErrorType = FFMS_ERROR_SUCCESS; ErrInfo.SubType = FFMS_ERROR_SUCCESS; // SetLogLevel(); try { LoadAudio(filename); } catch (...) { Close(); throw; } }
void CResourceManager::StartUp(void) { //SDL_Image if ( !IMG_Init(IMG_INIT_PNG) ) { CCoreEngine::Instance().GetLogManager().LogOutput( LOG_INFO, LOGSUB_RESOURCES,"Starting Up! (FAILED LOADING SDL_Image)"); } else { CCoreEngine::Instance().GetLogManager().LogOutput( LOG_INFO, LOGSUB_RESOURCES,"Starting Up! SDL_Image Loaded!"); } LoadTextures(); LoadAudio(); }
void CMixereView::OnDropFiles(CChannel *Chan, HDROP hDropInfo) { char Path[MAX_PATH]; UINT Files = DragQueryFile(hDropInfo, -1, 0, 0); DragQueryFile(hDropInfo, 0, Path, MAX_PATH); CString MixerExt; GetExtension(MixerExt); CStringArray ChanExt; CChannel::GetExtensionList(ChanExt); int Pos = Chan != NULL ? Chan->GetIndex() : GetItemCount(); // assume any non-mixer files are audio files CStringArray LoadErr; CStringArray FormatErr; for (UINT i = 0; i < Files; i++) { DragQueryFile(hDropInfo, i, Path, MAX_PATH); if (stricmp(PathFindExtension(Path), MixerExt)) { for (int j = 0; j < ChanExt.GetSize(); j++) { if (!stricmp(PathFindExtension(Path), ChanExt[j])) break; } if (j < ChanExt.GetSize()) { if (!LoadAudio(Pos++, Path)) AddStringUnique(LoadErr, Path); } else AddStringUnique(FormatErr, Path); } } // if audio files couldn't be loaded, display error message if (LoadErr.GetSize()) MsgBoxStrList(LDS(CANT_LOAD_AUDIO), LoadErr); // if audio files had invalid formats, display error message if (FormatErr.GetSize()) MsgBoxStrList(LDS(BAD_FILE_FORMAT), FormatErr); // now open mixer files if any for (i = 0; i < Files; i++) { DragQueryFile(hDropInfo, i, Path, MAX_PATH); if (!stricmp(PathFindExtension(Path), MixerExt)) AfxGetApp()->OpenDocumentFile(Path); } }
// Main function int main( int argc, char ** argv ) { // Initialize the memory leak detector for Win32 only (ignored by default in linux) bitInitMemoryLeak( BIT_NULL ); // Setting the absolute path in order to read files. Bit::SetAbsolutePath( argv[ 0 ] ); // Initialize the application if( LoadAudio( ) != BIT_OK || LoadInput( ) != BIT_OK ) { return CloseApplication( 0 ); } while( 1 ) { // Update the keyboard pKeyboard->Update( ); // Should we exit the program? if( pKeyboard->KeyIsJustReleased( Bit::Keyboard::Key_Escape ) ) { break; } // Play sound if( pKeyboard->KeyIsJustReleased( Bit::Keyboard::Key_P ) ) { pAudio->Play( ); } } // We are done bitTrace( "Closing the program.\n" ); return CloseApplication( 0 ); }
void CMixereView::LoadAudio() { CFileDialog fd(TRUE, ".wav", NULL, OFN_ALLOWMULTISELECT | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, CChannel::GetFileFilter()); // prepare OPENFILENAME struct for multiple select CString Buffer; const BUFSIZE = 0x7fff; LPTSTR FileBuf = Buffer.GetBufferSetLength(BUFSIZE); ZeroMemory(FileBuf, BUFSIZE); fd.m_ofn.lpstrFile = FileBuf; fd.m_ofn.nMaxFile = BUFSIZE; fd.m_ofn.nFileOffset = 0; CString Title(LDS(LOAD_AUDIO)); fd.m_ofn.lpstrTitle = Title; // display the dialog int retc = fd.DoModal(); int Pos = m_CurPos; if (retc == IDOK) { // iterate through the results CStringArray ErrPath; POSITION FilePos; FilePos = fd.GetStartPosition(); while (FilePos != NULL) { CString Path = fd.GetNextPathName(FilePos); if (!LoadAudio(Pos++, Path)) AddStringUnique(ErrPath, Path); } // if audio files couldn't be opened, display error message if (ErrPath.GetSize()) MsgBoxStrList(LDS(CANT_LOAD_AUDIO), ErrPath); } else { if (CommDlgExtendedError()) AfxMessageBox(LDS(FILE_DIALOG_ERROR)); } }
void CMixereView::OnLoadAudio() { LoadAudio(); }
bool AudioManager::LoadContent( int sfxChannelCount, int musicChannelCount ) { //ZeroMemory(&m_3dSounds, sizeof(Audio3dInfo)); m_sfxChannelCount = sfxChannelCount; m_musicChannelCount = musicChannelCount; if( !LoadSubmixes() ) { return false; } //details of the current audio device, hardware XAUDIO2_DEVICE_DETAILS details; m_audioEngine->GetDeviceDetails(0, &details); m_sound3D.nChannels = details.OutputFormat.Format.nChannels; m_sound3D.dwChannelMask = details.OutputFormat.dwChannelMask; //initialize 3dsound Handler float SPEEDOFSOUND = 343.5f; X3DAudioInitialize(details.OutputFormat.dwChannelMask, SPEEDOFSOUND, m_audio3dHandle); //SETUP LISTENER ///initial values m_sound3D.Emitter.push_back(Audio3dEmitter()); m_sound3D.Listener.Position = floatToa3dfloat(XMFLOAT3(0, 0, 0)); m_sound3D.Listener.OrientFront = floatToa3dfloat(XMFLOAT3(0, 0, 1)); m_sound3D.Listener.OrientTop = floatToa3dfloat(XMFLOAT3(0, 1, 0)); //Cone values m_sound3D.Listener.pCone = (X3DAUDIO_CONE*)&Listener_DirectionalCone; //EMITTER m_sound3D.Emitter[0].m_emitter.pCone = &m_sound3D.emitterCone; m_sound3D.Emitter[0].m_emitter.pCone->InnerAngle = 0.0f; // Setting the inner cone angles to X3DAUDIO_2PI and // outer cone other than 0 causes // the emitter to act like a point emitter using the // INNER cone settings only. m_sound3D.Emitter[0].m_emitter.pCone->OuterAngle = 0.0f; // Setting the outer cone angles to zero causes // the emitter to act like a point emitter using the // OUTER cone settings only. m_sound3D.Emitter[0].m_emitter.pCone->InnerVolume = 0.0f; m_sound3D.Emitter[0].m_emitter.pCone->OuterVolume = 1.0f; m_sound3D.Emitter[0].m_emitter.pCone->InnerLPF = 0.0f; m_sound3D.Emitter[0].m_emitter.pCone->OuterLPF = 1.0f; m_sound3D.Emitter[0].m_emitter.pCone->InnerReverb = 0.0f; m_sound3D.Emitter[0].m_emitter.pCone->OuterReverb = 1.0f; m_sound3D.Emitter[0].m_emitter.Position = floatToa3dfloat(XMFLOAT3(0, 0, 5)); m_sound3D.Emitter[0].m_emitter.OrientFront = floatToa3dfloat(XMFLOAT3(0, 0, 1)); m_sound3D.Emitter[0].m_emitter.OrientTop = floatToa3dfloat(XMFLOAT3(0, 1, 0)); m_sound3D.Emitter[0].m_emitter.ChannelCount = INPUTCHANNELS; m_sound3D.Emitter[0].m_emitter.ChannelRadius = 1.0f; m_sound3D.Emitter[0].m_emitter.pChannelAzimuths = m_sound3D.emitterAzimuths; // Use of Inner radius allows for smoother transitions as // a sound travels directly through, above, or below the listener. // It also may be used to give elevation cues. m_sound3D.Emitter[0].m_emitter.InnerRadius = 2.0f; m_sound3D.Emitter[0].m_emitter.InnerRadiusAngle = X3DAUDIO_PI / 4.0f;; m_sound3D.Emitter[0].m_emitter.pVolumeCurve = (X3DAUDIO_DISTANCE_CURVE*)&X3DAudioDefault_LinearCurve; m_sound3D.Emitter[0].m_emitter.pLFECurve = (X3DAUDIO_DISTANCE_CURVE*)&Emitter_LFE_Curve; m_sound3D.Emitter[0].m_emitter.pLPFDirectCurve = NULL; // use default curve m_sound3D.Emitter[0].m_emitter.pLPFReverbCurve = NULL; // use default curve m_sound3D.Emitter[0].m_emitter.pReverbCurve = (X3DAUDIO_DISTANCE_CURVE*)&Emitter_Reverb_Curve; m_sound3D.Emitter[0].m_emitter.CurveDistanceScaler = 14.0f; m_sound3D.Emitter[0].m_emitter.DopplerScaler = 1.0f; //DPS m_sound3D.Emitter[0].dspSettings.SrcChannelCount = INPUTCHANNELS; m_sound3D.Emitter[0].dspSettings.DstChannelCount = m_sound3D.nChannels; m_sound3D.Emitter[0].dspSettings.pMatrixCoefficients = m_sound3D.matrixCoefficients; if (!LoadAudio()) { return false; } ////LOOP SOUND //XAUDIO2_BUFFER playerBuffer = { 0 }; //shared_ptr<ImplData> soundData = m_3dTrackList[sound3dIndexMap["3ds_Pboost.wav"]]; //playerBuffer.AudioBytes = soundData->g_audioData.xaBuffer()->AudioBytes; //playerBuffer.pAudioData = soundData->g_audioData.xaBuffer()->pAudioData; //playerBuffer.Flags = XAUDIO2_END_OF_STREAM; //playerBuffer.LoopCount = XAUDIO2_LOOP_INFINITE; ////Get rid of what ever was queued to play ////soundData->g_sourceVoice->FlushSourceBuffers(); //soundData->g_sourceVoice->SubmitSourceBuffer(&playerBuffer); //soundData->g_sourceVoice->Start(0); //AllocConsole(); //freopen("CONOUT$", "w", stdout); return true; }
FrkSound::FrkSound(const tchar* audioPath) { LoadAudio(audioPath); }
void Project::ReloadAudio() { if (audio_provider) LoadAudio(audio_file); }
void initRecord(){ // Attempt to load some sound data, to encode into the output movie's // audio stream. bool hasAudio = false; audioBuffer = NULL; LoadAudio(&hasAudio, &audioBits, &audioChannels, &audioFormat, &audioRate, &audioBuffer, &audioBufferSize); if (!hasAudio) { printf("Warning: Failed to load audio test file: chimes.raw\n"); printf(" The audio encoding tests will be skipped.\n"); } // Make sure the API version of Revel we're compiling against matches the // header files! This is terribly important! if (REVEL_API_VERSION != Revel_GetApiVersion()) { printf("ERROR: Revel version mismatch!\n"); printf("Headers: version %06x, API version %d\n", REVEL_VERSION, REVEL_API_VERSION); printf("Library: version %06x, API version %d\n", Revel_GetVersion(), Revel_GetApiVersion()); exit(1); } // Create an encoder revError = Revel_CreateEncoder(&encoderHandle); if (revError != REVEL_ERR_NONE) { printf("Revel Error while creating encoder: %d\n", revError); exit(1); } // Set up the encoding parameters. ALWAYS call Revel_InitializeParams() // before filling in your application's parameters, to ensure that all // fields (especially ones that you may not know about) are initialized // to safe values. Revel_InitializeParams(&revParams); revParams.width = width; revParams.height = height; revParams.frameRate = 25.0f; revParams.quality = 1.0f; revParams.codec = REVEL_CD_XVID; revParams.hasAudio = hasAudio ? 1 : 0; revParams.audioChannels = audioChannels; revParams.audioRate = audioRate; revParams.audioBits = audioBits; revParams.audioSampleFormat = audioFormat; // Initiate encoding revError = Revel_EncodeStart(encoderHandle, filename, &revParams); if (revError != REVEL_ERR_NONE) { printf("Revel Error while starting encoding: %d\n", revError); exit(1); } // Draw and encode each frame. frame.width = width; frame.height = height; frame.bytesPerPixel = 4; frame.pixelFormat = REVEL_PF_RGBA; frame.pixels = new int[width*height]; }
int main(int argc, char *argv[]) { const char *filename = "checkers.avi"; int numFrames = 64; Revel_Error revError; // Make sure the encoder is valid if (!Revel_IsEncoderValid(encoderHandle)) { return -1; } // Attempt to load some sound data, to encode into the output movie's // audio stream. bool hasAudio = false; char *audioBuffer = NULL; int audioBufferSize = 0; LoadAudio(&hasAudio, &audioBuffer, &audioBufferSize); if (!hasAudio) { printf("Warning: Failed to load audio test file: chimes.raw\n"); printf(" The audio encoding tests will be skipped.\n"); } // Initiate encoding revError = Revel_EncodeStart(encoderHandle, filename); if (revError != REVEL_ERR_NONE) { printf("Revel Error while starting encoding: %d\n", revError); exit(1); } // Draw and encode each frame. Revel_VideoFrame frame; frame.width = width; frame.height = height; frame.bytesPerPixel = 4; frame.pixelFormat = REVEL_PF_RGBA; frame.pixels = new int[width*height]; memset(frame.pixels, 0, width*height*4); for(int i=0; i<numFrames; ++i) { DrawFrame(frame.width, frame.height, 0xFF000000 + 0x000004*i, i, i, (int*)frame.pixels); int frameSize = 0; revError = Revel_EncodeFrame(encoderHandle, &frame, &frameSize); if (revError != REVEL_ERR_NONE) { printf("Revel Error while writing frame: %d\n", revError); exit(1); } printf("Frame %d of %d: %d bytes\n", i+1, numFrames, frameSize); } // Encode the audio track. NOTE that each call to Revel_EncodeAudio() // *appends* the new audio data onto the existing audio track. There is // no synchronization between the audio and video tracks! If you want // the audio to start on frame 60, you need to manually insert 60 frames // worth of silence at the beginning of your audio track! // // To demonstrate this, we'll encode the audio buffer twice. Note that // the two chimes play immediately when the movie starts, one after the // other, even though we're encoding them "after" all the video frames. int totalAudioBytes = 0; revError = Revel_EncodeAudio(encoderHandle, audioBuffer, audioBufferSize, &totalAudioBytes); revError = Revel_EncodeAudio(encoderHandle, audioBuffer, audioBufferSize, &totalAudioBytes); if (revError != REVEL_ERR_NONE) { printf("Revel Error while writing audio: %d\n", revError); exit(1); } printf("Encoded %d bytes of audio\n", totalAudioBytes); // Finalize encoding. If this step is skipped, the output movie will be // unviewable! int totalSize = 0; revError = Revel_EncodeEnd(encoderHandle, &totalSize); if (revError != REVEL_ERR_NONE) { printf("Revel Error while ending encoding: %d\n", revError); exit(1); } printf("%s written: %dx%d, %d frames, %d bytes\n", filename, width, height, numFrames, totalSize); // Final cleanup. Revel_DestroyEncoder(encoderHandle); if (audioBuffer != NULL) delete [] audioBuffer; delete [] (int*)frame.pixels; return 0; }
HRESULT FrkSound::Play(const pchar* audioPath, bool isLoop, DWORD priority) { LoadAudio(audioPath); return m_hSoundBuffer->Play(0, priority, isLoop & DSBPLAY_LOOPING); }
void CResourceManager::StartUp(void) { LoadTextures(); LoadAudio(); }