Click here to Skip to main content
15,880,503 members
Please Sign up or sign in to vote.
2.25/5 (4 votes)
hello
i want to play many sounds simultaneously with Directshow. but first, i have to select for every sound a specific output device (i have many output devices ).
any idea about selecting devices before playing sounds , thanks . this is important parts of my program

XML
#include <windows.h>
#include <mmsystem.h>
#include <streams.h>

#include <windows.h>
#include <mmsystem.h>
#include <streams.h>

class Mp3
{
private:
IBaseFilter * pif;
IGraphBuilder * pigb;
IMediaControl * pimc;
IMediaEventEx * pimex;

bool ready;

public:
Mp3();
~Mp3();

void Load(LPSTR filename);
void Cleanup();

void Play();
void Pause();
void Stop();
};


// MP3-Wav.cpp

#include "Mp3.h"


Mp3::Mp3()
{
pif = NULL;
pigb = NULL;
pimc = NULL;
pimex = NULL;

ready = false;

CoInitialize(NULL);
}

Mp3::~Mp3()
{
Cleanup();
}

void Mp3::Cleanup()
{
CoUninitialize();

if (pimc)
pimc->Stop();

if(pif)
{
pif->Release();
pif = NULL;
}

if(pigb)
{
pigb->Release();
pigb = NULL;
}

if(pimc)
{
pimc->Release();
pimc = NULL;
}

if(pimex)
{
pimex->Release();
pimex = NULL;
}
}

void Mp3::Load(LPSTR szFile)
{
WCHAR wFile[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, szFile, -1, wFile, MAX_PATH);

if (SUCCEEDED(CoCreateInstance( CLSID_FilterGraph,
NULL,
CLSCTX_INPROC_SERVER,
IID_IGraphBuilder,
(void **)&this->pigb)))
{
pigb->QueryInterface(IID_IMediaControl, (void **)&pimc);
pigb->QueryInterface(IID_IMediaEventEx, (void **)&pimex);

if (SUCCEEDED(pigb->RenderFile(wFile, NULL)))
{
ready = true;
}
}
}

void Mp3::Play()
{
if (ready)
{
pimc->Run();
}
}

void Mp3::Pause()
{
if (ready)
{
pimc->Pause();
}
}

void Mp3::Stop()
{
if (ready)
{
pimc->Stop();
}
}

int main ()
{
MP3 classmp3;
classmp3.play()
.
.
.
}
Posted
Updated 2-Aug-11 3:15am
v3
Comments
TRK3 6-Jul-11 14:03pm    
Does it matter which device you pick for a given sound? Are all the devices equivalent, so that it doesn't matter which one you use to play which sound? Or do some devices only play some sounds?
kinani 16-Aug-11 6:03am    
Thanks TRK3 , i have resolved the problem
kinani 6-Jul-11 16:19pm    
Hello TRK3
all devices are equivalent i have tried a function from directsound ( soundenumerator) that allows to enumerate the 5 devices that i have but i dont know how select a devives from this list to a sound . i use directshow to play sounds ( mp3 and wav ) with filters and winmm.lib ( wavformatex )to generate and play self generated sound .

Perhaps this is the family of functions that you're looking for? I've certainly used them in the past for playback and recording.

Waveform-Audio Interface--->Devices and Data Types[^]
 
Share this answer
 
Take a look at this link[^].

It is not exactly what you are asking, but it could give you some advice.

Anyway... more than post an almost identical question a month after the original one[^] it would be nice to see that you've tried to make it by yourself... googling and reading information in the Internet... and at least you should have posted a little bit more of information... I don't know... a code snippet, some ideas you have tested or similar...

kinani you should think about it... Asking the right question and doing it right is half the answer... and here the one that wants to broadcast sound to different audio devices is you...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900