Archived

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

DirectAudio

This topic is 4961 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

Well DirectAudio doesn''t really support any file methods. You give it raw PCM data and some info on it''s format and it chugs away. I believe that some other parts of DirectX may allow you to load MP3s and such, but personally I prefer just using the Ogg Vorbis libraries directly. Vorbisfile is REALLY easy to use: take a look at the documentation at:
http://www.xiph.org/ogg/vorbis/doc/vorbisfile/index.html

Share this post


Link to post
Share on other sites
direct show can play mp3s, midis, wavs quite easily

just finding info on how isnt
.header
.cpp


#include <dshow.h>

class Music;

class AMUSIC_API Music {
private:
IGraphBuilder *g_pGraphBuilder;
IMediaControl *g_pMediaControl;
IMediaSeeking *g_pMediaSeeking;
IBasicAudio *g_pBasicAudio;
public:
Music();
~Music();
void load(char filename[]);
void play();
void stop();
void getPosition(LONGLONG * position,LONGLONG * stopPosition);
long getVolume();
long getBalance();
void setPosition(LONGLONG position);
void setVolume(long volume);
void setBalance(long balance);
};




#define _WIN32_DCOM
#define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } }

Music::Music()
{
if(SUCCEEDED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)))
if(SUCCEEDED(CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC, IID_IGraphBuilder, reinterpret_cast<void **>(&g_pGraphBuilder))))
if(SUCCEEDED(g_pGraphBuilder->QueryInterface(IID_IMediaControl,reinterpret_cast<void **>(&g_pMediaControl))))
if(SUCCEEDED(g_pGraphBuilder->QueryInterface(IID_IMediaSeeking,reinterpret_cast<void **>(&g_pMediaSeeking))))
g_pGraphBuilder->QueryInterface(IID_IBasicAudio,reinterpret_cast<void **>(&g_pBasicAudio));
}
Music::~Music()
{
SAFE_RELEASE(g_pGraphBuilder);
SAFE_RELEASE(g_pMediaControl);
SAFE_RELEASE(g_pMediaSeeking);
SAFE_RELEASE(g_pBasicAudio);
CoUninitialize();
}
void Music::load(char filename[])
{
if(g_pGraphBuilder!=NULL)
{
WCHAR wFilename[MAX_PATH];
MultiByteToWideChar(CP_ACP,0,filename,-1,wFilename,MAX_PATH);
LPCWSTR lwFilename= wFilename;
g_pGraphBuilder->RenderFile(lwFilename,NULL);
}
}
void Music::play()
{
if(g_pMediaControl!=NULL)
g_pMediaControl->Run();
}
void Music::stop()
{
if(g_pMediaControl!=NULL)
g_pMediaControl->Stop();
}
void Music::getPosition(LONGLONG * position,LONGLONG * stopPosition)
{
if(g_pMediaSeeking!=NULL)
g_pMediaSeeking->GetPositions(position, stopPosition);
}
long Music::getVolume()
{
if(g_pBasicAudio!=NULL)
{
long volume;
g_pBasicAudio->get_Volume(&volume);
return volume;
}

return 0;
}
long Music::getBalance()
{
if(g_pBasicAudio!=NULL)
{
long balance;
g_pBasicAudio->get_Balance(&balance);
return balance;
}

return 0;
}
void Music::setPosition(LONGLONG position)
{
if(g_pMediaSeeking!=NULL)
g_pMediaSeeking->SetPositions(&position, AM_SEEKING_AbsolutePositioning ,
NULL, AM_SEEKING_NoPositioning);
}
void Music::setVolume(long volume)
{
if(g_pBasicAudio!=NULL)
g_pBasicAudio->put_Volume(volume);
}
void Music::setBalance(long balance)
{
if(g_pBasicAudio!=NULL)
g_pBasicAudio->put_Balance(balance);
}

Share this post


Link to post
Share on other sites