Jump to content
  • Advertisement
Sign in to follow this  
Dead_Zone

DirectMusic

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

this code if for a console im deving on but im having problems getting direct music to work and when i put my DirectMusic funtions in my main loop the triangle and blue background doesnt render the console uses DirectX8
#include <xtl.h>
#include <Dmusici.h>


LPDIRECT3D8 g_pD3D = NULL;                      // DirectX Object 
LPDIRECT3DDEVICE8 g_pD3DDevice = NULL;          // Screen Object 
IDirectMusicLoader8* g_pLoader = NULL;
IDirectMusicPerformance8* g_pPerformance = NULL;
IDirectMusicSegment8* g_pSegment = NULL;

void audinit()
{
	g_pPerformance->InitAudioX( DMUS_APATH_DYNAMIC_3D, 64, NULL, NULL );

	g_pSegment->Download( g_pPerformance );
	
    // Tell DirectMusic where the default search path is
	g_pPerformance->SetDefaultAudioPath( IDirectMusicAudioPath                ("E:\\samples\\media\\"));
}

void audplay()
{
		g_pPerformance->PlaySegmentEx(
		g_pSegment,
		NULL,
		NULL,
		0,
		0,
		NULL,
		NULL,
		NULL
	);
}

void InitialiseD3D() 
{ 

    g_pD3D = Direct3DCreate8(D3D_SDK_VERSION); 

    //Create a structure to hold the settings for our device 
    D3DPRESENT_PARAMETERS d3dpp; 
    ZeroMemory(&d3dpp, sizeof(d3dpp)); 

    //Fill the structure. 
    // Set fullscreen 640x480x32 mode 
      d3dpp.BackBufferWidth = 640; 
      d3dpp.BackBufferHeight = 480; 
      d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; 

   
      d3dpp.BackBufferCount = 1; 

     
      d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; 

    
    g_pD3D->CreateDevice(0, D3DDEVTYPE_HAL, NULL, 
                                   D3DCREATE_HARDWARE_VERTEXPROCESSING, 
                                                   &d3dpp, &g_pD3DDevice); 
} 
void CleanUp() 
{ 
    g_pD3DDevice->Release(); 
    g_pD3D->Release(); 
}


LPDIRECT3DVERTEXBUFFER8 g_pVertexBuffer = NULL; 
struct CUSTOMVERTEX 
{ 
    FLOAT x, y, z, rhw; 
    DWORD colour; 
}; 
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE) 
void DrawTriangle() 
{ 
    VOID* pVertices; 

    
    CUSTOMVERTEX cvVertices[] = 
    { 
        {250.0f, 100.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255, 0, 0),}, //Vertex 1 - Red (250, 100) 
        {400.0f, 350.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 255, 0),}, //Vertex 2 - Green (400, 350) 
        {100.0f, 350.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, 255),}, //Vertex 3 - Blue (100, 350) 
    }; 


    g_pD3DDevice->CreateVertexBuffer(3 * sizeof(CUSTOMVERTEX), 
0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVertexBuffer); 

 
    g_pVertexBuffer->Lock(0, sizeof(cvVertices), (BYTE**)&pVertices, 0); 

    memcpy(pVertices, cvVertices, sizeof(cvVertices)); 


    g_pVertexBuffer->Unlock(); 

    
    g_pD3DDevice->SetStreamSource(0, g_pVertexBuffer, sizeof(CUSTOMVERTEX)); 
    g_pD3DDevice->SetVertexShader(D3DFVF_CUSTOMVERTEX); 
    g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1); 

              
             g_pVertexBuffer->Release(); 
} 




void _cdecl main()
{
	audinit();
	InitialiseD3D();

	while(true)
	{
		g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0);

			g_pD3DDevice->BeginScene();

				DrawTriangle();
				

			g_pD3DDevice->EndScene();
			g_pD3DDevice->Present(NULL, NULL, NULL, NULL);
					
				audplay();
	}
	CleanUp();
}

[Edited by - Coder on September 12, 2005 3:43:51 AM]

Share this post


Link to post
Share on other sites
Advertisement
So it works without the DirectMusic code being called?
Do you actually run the window message pump (PeekMessage(), etc), or did you just leave it out of the code you posted?

Share this post


Link to post
Share on other sites
ahh my friend i dont use the windows api just directx and the XTL framework of which the xbox uses i just need to know why my music isnt working and why when i put my functions in the main loop my triangle and blue background doesnt render

Share this post


Link to post
Share on other sites
Does the sound play?
Does the sound load without error?

I see calling audplay() every frame like that might lead to unpredictable behaviour. Try calling it just once right before you enter the main loop.

If the sound is not loading correctly, when you try to play it the app might be crashing. Check that none of those DX functions are returning error messages.

I'm assuming you have the XDK, which I belive has a couple of audio examples in it. I would check those out and see what they do.

Also, it looks like you may have some other potentially problematic code in there too. Like it looks like you Release your vertex buffer every frame? Can you edit your post to use the source tags (it's a little tough to follow as is)? ie.
 // Your code here

[/source]

Matt Hughson

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!