0
0

Hello,
How play (C++) a stream on 4 speakers ?
I have a Soundblaster live and I want to play a stream (MP3) on 4 speakers
With 2 Speakers it is simple but 4 it doesn’t work

How works FSOUND_SPEAKERMODES ?
What is my error in this code ?
Please Help me
Thank u

include <stdio.h>

include <stdlib.h>

include <conio.h>

include <windows.h>

include “fmod.h”

int main()
{
FSOUND_STREAM *MP3Stream;

bool SPACE3D=true; // 4 Speakers

char key;

int        channel = -1;


FSOUND_SetOutput(FSOUND_OUTPUT_DSOUND); // DIRECT SOUND
FSOUND_SetDriver(FSOUND_CAPS_HARDWARE);  // HARDWARE
FSOUND_SetMixer(FSOUND_MIXER_AUTODETECT);
FSOUND_SetSpeakerMode(FSOUND_SPEAKERMODE_QUAD);    // Set 4 Speakers ? ? ?
FSOUND_Init(44100, 32, 0);



MP3Stream = FSOUND_Stream_OpenFile("Dune.mp3",FSOUND_NORMAL , 0); 

printf("=========================================================================\n");
printf("      ESC    Quit\n");
printf("=========================================================================\n");

channel =  FSOUND_Stream_Play(FSOUND_FREE, MP3Stream );

// ==========================================================================================
// MAIN LOOP
// ==========================================================================================
printf("4 Speakers by Default\n");
printf(" \"a\" Pour Activer Son 2 ou 4 Speakers\n");
do
{
    if (kbhit())
    {
        key = getch();

        if (key == 'a') 
        {

            if (SPACE3D)
            {
                printf("2 Speakers\n");
                SPACE3D=!SPACE3D;
                FSOUND_SetSpeakerMode(FSOUND_SPEAKERMODE_STEREO);
                FSOUND_Update();


            }
            else
            {

                printf("4 Speakers\n");
                SPACE3D=!SPACE3D;
                FSOUND_SetSpeakerMode(FSOUND_SPEAKERMODE_QUAD);
                FSOUND_Update();

            }
        }



    }

} while (key != 27);

printf("\n");

FSOUND_Stream_Stop(MP3Stream); 
FSOUND_Stream_Close(MP3Stream); 

FSOUND_Close();   
return 0;

}

  • You must to post comments
0
0

But with DirectSound SDK you can play a mp3 on Four Speakers with no problem then why Fmod doesn’t

  • You must to post comments
0
0

false with direct show (a layer of Direct X SDK) you can play easy a mp3

And I prove it

Fmod is a good sound library

// AudioDll.cpp : Defines the entry point for the DLL application.
//

include “stdafx.h”

include “AudioDll.h”

include <atlbase.h>

include <process.h>

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}

// This is an example of an exported variable
AUDIODLL_API int nAudioDll=0;

// This is an example of an exported function.
AUDIODLL_API int fnAudioDll(void)
{
return 42;
}

// This is the constructor of a class that has been exported.
// see AudioDll.h for the class definition
CAudioDll::CAudioDll(char *FileName)
{
HRESULT hr = S_OK;
WCHAR wFile[MAX_PATH];

pGraph=NULL;
pMediaControl=NULL;
pEvent=NULL;
pPosition=NULL;
pSon=NULL;
pVW=NULL;
pParams=NULL;
ThreadLoopON=false;
hThreadLoop=NULL;
LoopON=false;
Action=STOP;

CoInitialize(NULL);
 // Create the filter graph manager and query for interfaces.
CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, 
                    IID_IGraphBuilder, (void **)&amp;pGraph);
pGraph-&gt;QueryInterface(IID_IMediaControl, (void **)&amp;pMediaControl);
pGraph-&gt;QueryInterface(IID_IMediaEvent, (void **)&amp;pEvent);
pGraph-&gt;QueryInterface(IID_IMediaPosition,(void **)&amp;pPosition);
pGraph-&gt;QueryInterface(IID_IBasicAudio,(void **)&amp;pSon);
pGraph-&gt;QueryInterface(IID_IVideoWindow,(void **)&amp;pVW);

// Build the graph. IMPORTANT: Change string to a file on your system.
USES_CONVERSION;
wcscpy(wFile, T2W(FileName));
hr=pGraph-&gt;RenderFile(wFile, NULL);

if (hr==S_OK) // construction du graphe OK
{
    hr = pVW-&gt;put_MessageDrain((OAHWND) NULL); 
    if (FAILED(hr)) // C'est un graphe Audio
    {
        ObjetOK=true;
    }
    else // Ce n'est pas un graphe Audio
    {
        ObjetOK=false;
    }
}
else ObjetOK=false;

}

//////////////////////////////////////////////////////////////////////
CAudioDll::~CAudioDll()
{
//LoopON=true;
// Loop();

Stop();
End();
if (hThreadLoop) 
{
    TerminateThread(hThreadLoop,0);
    CloseHandle(hThreadLoop);
}

if (pMediaControl) pMediaControl-&gt;Release();
if (pEvent)        pEvent-&gt;Release();
if (pPosition)     pPosition-&gt;Release();
if (pSon)          pSon-&gt;Release();
if (pVW)           pVW-&gt;Release();
if (pGraph)        pGraph-&gt;Release();

if (pParams) 
{
    delete pParams;
    pParams=NULL;
}

CoUninitialize();

}
//////////////////////////////////////////////////////////////////////
void CAudioDll::Play()
{
if (ObjetOK)
{
if (Action!=PAUSE) Begin();
pMediaControl->Run();
Action=PLAY;
}

}
//////////////////////////////////////////////////////////////////////
void CAudioDll::Pause()
{
if (ObjetOK)
{
if (Action==PLAY)
{
pMediaControl->Pause();
if (ThreadLoopON) SuspendThread(hThreadLoop);
Action=PAUSE;
}
else if (Action==PAUSE)
{
pMediaControl->Run();
if (ThreadLoopON) ResumeThread(hThreadLoop);
Action=PLAY;
}

}

}
//////////////////////////////////////////////////////////////////////
void CAudioDll::Stop()
{
if (ObjetOK)
{
pMediaControl->Stop();
Begin();
Action=STOP;
}
}
//////////////////////////////////////////////////////////////////////
double CAudioDll::Duree()
{

double RetourVal=0;
if (ObjetOK)
{
    pPosition-&gt;get_Duration(&amp;RetourVal);
}
return RetourVal;

}
//////////////////////////////////////////////////////////////////////
double CAudioDll::GetCurrentPosition()
{
double RetourVal=0;
if (ObjetOK)
{
pPosition->get_CurrentPosition(&RetourVal);
}
return RetourVal;

}
//////////////////////////////////////////////////////////////////////
void CAudioDll::SetPosition(double NewPos)
{
if (ObjetOK)
{
if (NewPos<= Duree() )
pPosition->put_CurrentPosition(NewPos);
}

}
//////////////////////////////////////////////////////////////////////
void CAudioDll::Begin()
{
if (ObjetOK)
{
SetPosition(0);
}
}
//////////////////////////////////////////////////////////////////////
void CAudioDll::End()
{
if (ObjetOK)
{
SetPosition(Duree());
}
}
//////////////////////////////////////////////////////////////////////
void CAudioDll::SetVolume(long Volume)
{
if (ObjetOK)
{
if (Volume<VOLUMEMIN) Volume=VOLUMEMIN;
if (Volume>VOLUMEMAX) Volume=VOLUMEMAX;
pSon->put_Volume(Volume);
}
}
//////////////////////////////////////////////////////////////////////
void CAudioDll::Loop()
{
if (ObjetOK)
{
if (LoopON)
{
LoopON=false;
if (hThreadLoop)
{
TerminateThread(hThreadLoop,0);
CloseHandle(hThreadLoop);
}

    }
    else
    {
        LoopON=true;            
        if (!ThreadLoopON)
        {
            ThreadLoopON=true;

            if (pParams) delete pParams;
            pParams=new ParamsAudio;
            pParams-&gt;pEvent=pEvent;
            pParams-&gt;pAudio=this;
            hThreadLoop=CreateThread(NULL,
                                 0,
                                 (LPTHREAD_START_ROUTINE)ThreadLoop,
                                 pParams,
                                 0,
                                 NULL);


        }

    }

}

}
//////////////////////////////////////////////////////////////////////
long CAudioDll::GetVolume()
{
long vol=0;
if (ObjetOK)
{
pSon->get_Volume(&vol);
}
return vol;
}
//////////////////////////////////////////////////////////////////////
void CAudioDll::SetBalance(long Position)
{

if (ObjetOK)
{
    pSon-&gt;put_Balance(Position);
}

}
//////////////////////////////////////////////////////////////////////
long CAudioDll::GetBalance()
{
long Balance=0;
if (ObjetOK)
{
pSon->get_Balance(&Balance);
}
return Balance;
}

//////////////////////////////////////////////////////////////////////
void ThreadLoop(void *pParams)
{

long evCode;
ParamsAudio *params=(ParamsAudio *)pParams;

if ( params-&gt;pAudio-&gt;IsOK() )
{
    while (params-&gt;pAudio-&gt;LoopON)
    {
        // Wait for completion. 
        params-&gt;pEvent-&gt;WaitForCompletion(INFINITE, &amp;evCode);
        params-&gt;pAudio-&gt;Stop();
        params-&gt;pAudio-&gt;Action=PLAY;
        if (params-&gt;pAudio-&gt;LoopON)
        {
            if (params-&gt;pAudio-&gt;Action==PLAY)
            {
                params-&gt;pAudio-&gt;Play();
            }
        }
    }
    params-&gt;pAudio-&gt;ThreadLoopON=false;
    ExitThread(0);

}

}
//////////////////////////////////////////////////////////////////////

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.