Archived

This topic is now archived and is closed to further replies.

C/C++ sound engine that supports mp3's

This topic is 5423 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Guest Anonymous Poster
you can play mp3s using DirectShow in a few lines of code

Share this post


Link to post
Share on other sites
You can play an mp3 in three lines of code in FMOD.


  
FSOUND_Init(44100, 32, 0);
FSOUND_STREAM * stream = FSOUND_Stream_OpenFile("song.mp3", FSOUND_16BITS | FSOUND_STEREO, 0)
FSOUND_Stream_Play(FSOUND_FREE, stream);


Alan

Share this post


Link to post
Share on other sites
I would *really* suggest error checking (and probably closing the stream when you''re finished with it...).

I only started looking at FMOD two days ago and I have already got a full sound effects and background music system running. Its fast too, on my 1.7ghz p4 it runs at about .075% (three quarters of one percent) processor usage.

Alan

Share this post


Link to post
Share on other sites
Use Directshow ! it''s so easy... you wrap it to a class and done. Here, some code :


  
// INITIALIZATION //

IGraphBuilder* m_pGraph;
IMediaControl* m_pControl;

CoInitialize( NULL );

CoCreateInstance( CLSID_FilterGraph, NULL, CLSCTX_INPROC, IID_IGraphBuilder, (VOID**) &m_pGraph ) ));

m_pGraph->QueryInterface( IID_IMediaControl, (VOID**) &m_pControl ) ));


// LOADING //

WCHAR strFilename[256];
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, "tune.mp3, -1, strFilename, MAX_PATH );

m_pGraph->RenderFile( strFilename, NULL ) ));


// DURING GAME //

///////////////////////////////////////////////////////////


// Play //

m_pControl->Run();

// or Stop //

m_pControl->Stop();

///////////////////////////////////////////////////////////



// SHUTDOWN //

if (m_pControl)
{
m_pControl->Stop();
m_pControl->Release();
m_pControl = NULL;
}

if (m_pGraph)
{
//m_pGraph->Release();

m_pGraph = NULL;
}

CoUninitialize();




/* Bullmax */
-------------
Reality has many forms : good and evil, black and white, yin and yang.

Share this post


Link to post
Share on other sites
Not to mention the licensing issues surrounding MP3 itself. Using DirectShow is equivalent to allowing Microsoft to pick up the tab; that is, if you had any intention of taking the license seriously at all. Another alternative is Ogg Vorbis, which lacks licensing of any kind and is rumored to have better sound quality overall.

Share this post


Link to post
Share on other sites