Jump to content

  • Log In with Google      Sign In   
  • Create Account


liamf1986

Member Since 23 Sep 2009
Offline Last Active Apr 25 2013 05:06 AM
-----

Topics I've Started

Ogg Vorbis decoder

19 March 2013 - 11:30 AM

Hello,

 

I'm trying to implement a decoder for ogg vorbis audio files (.ogg). It all compiles and runs fine but the audio is mostly static.

It plays a second or two of the correct audio occasionally but is mostly just static noise.

 

I was wondering if anyone could see any problems in the code, see below.

 

// Defined in .h file
XAUDIO2_BUFFER m_xa;
WAVEFORMATEX m_wf;
 
 

bool COgg::load(const char* szFile, bool loop) { if (szFile == NULL) return false; FILE* file = NULL; OggVorbis_File m_oggFile; errno_t error; error = fopen_s(&file, szFile, "rb"); if (error != 0) return false; // Get info from .ogg file. if (ov_open_callbacks(file, &m_oggFile, NULL, 0, OV_CALLBACKS_DEFAULT) != 0) { fclose(file); return false; } vorbis_info* vInfo = ov_info(&m_oggFile, -1); memset(&m_wf, 0, sizeof(m_wf)); m_wf.cbSize = sizeof(m_wf); m_wf.nChannels = vInfo->channels; m_wf.wBitsPerSample = 16; // Ogg vorbis is always 16 m_wf.nSamplesPerSec = vInfo->rate; m_wf.nAvgBytesPerSec = m_wf.nChannels * 2 * m_wf.nSamplesPerSec; m_wf.nBlockAlign = m_wf.nChannels * 2; m_wf.wFormatTag = WAVE_FORMAT_PCM; // Get size of file. fseek(file, 0, SEEK_END); // Jump to end of file. long fileSize = ftell(file); // Store current position in file (the end). fseek(file, 0, SEEK_SET); // Jump back to the begining. int bitstream = 0; DWORD pos = 0; int ret = 1;
// Read the audio data from the opened .ogg file. char* m_data = new char[fileSize]; while (ret && pos<fileSize) { ret = ov_read(&m_oggFile, m_data+pos, fileSize-pos, 0, 2, 1, &bitstream); pos += ret; } m_xa.AudioBytes = fileSize; m_xa.pAudioData = reinterpret_cast<BYTE*>(m_data); m_xa.PlayBegin = 0; m_xa.PlayLength = 0; // Ignore the zero for now, it should be the length of the track. if (loop == true) { m_xa.LoopBegin = m_xa.PlayBegin; m_xa.LoopLength = m_xa.PlayLength; m_xa.LoopCount = -1; // -1 is an infinate loop. } // Kill the vorbis file. ov_clear(&m_oggFile); // close the file. fclose(file); return true; }

 

 


Odd ID3DXFont problem

20 February 2011 - 12:34 PM

Hello all,

I'm having an odd issue with ID3DXFont.
I'll start by posting an image of the problem and maybe someone will recognize it straight away,

Posted Image

That supposedly says Debug Mode....
This problem only occurs when the DrawText() function of any font object is only called once. If I draw another line later in the program both lines draw perfectly fine, as shown below,

Posted Image

The problem is localized to each instance of ID3DXFont, meaning I can create 2 instances of ID3DXFont draw 2 lines with one instance and they will draw fine but if I only draw one line with the other instance that line will draw incorrectly.

My Text drawing code is as follows;

device->ClearScreen(bgColor);
device->BeginScene();

spriteInterface->Begin(D3DXSPRITE_ALPHABLEND);

RECT fontPos;
SetRect(&fontPos, xPos, yPos, 100, 100);

debugText->DrawText(spriteInterface,
       	     	"Debug Mode",
                	-1,
                	&fontPos,
          		DT_LEFT | DT_NOCLIP,
          		D3DCOLOR_XRGB(255, 255, 255));

spriteInterface->End();

device->EndScene();
device->Present(NULL, NULL, NULL, NULL);

Greatly appreciate any help anyone can offer,
cheers Liam F

[DirectX] Bounding Box on a Frame Hierachy

27 October 2010 - 12:54 PM

Hey guys,
I've been working on my animated model class and i'm having an issue with calculating the AxisAlignedBoundingBox for the entire frame Hierachy.
I've got the bounding box being calculated upon loading the model, and it is working to an extent. The problem is the resulting box is too large for some reason.
The box is working in that it is the right shape and is adjusting itself as the model moves or rotates but its about 3-4x the size it should be.

The code calculating the Box is as follows,

This first part is at the end of the load function shortly after the call to D3DXLoadMeshHierarchyFromX()
Vector3 min = Vector3(0, 0, 0), max = Vector3(0, 0, 0);
FrameCalculateBoundingBox(pFrameRoot, &min, &max);
boundsBox.arrBoundsPoints[0] = Vector3(min.x, min.y, min.z);
boundsBox.arrBoundsPoints[1] = Vector3(max.x, min.y, min.z);
boundsBox.arrBoundsPoints[2] = Vector3(min.x, max.y, min.z);
boundsBox.arrBoundsPoints[3] = Vector3(max.x, max.y, min.z);
boundsBox.arrBoundsPoints[4] = Vector3(min.x, min.y, max.z);
boundsBox.arrBoundsPoints[5] = Vector3(max.x, min.y, max.z);
boundsBox.arrBoundsPoints[6] = Vector3(min.x, max.y, max.z);
boundsBox.arrBoundsPoints[7] = Vector3(max.x, max.y, max.z);


The following is the function that calls its self recursivly to loop through the hieracrhy and get the min and max vertex positions to use for the BoundingBox.
void AnimatedMesh::FrameCalculateBoundingBox(LPD3DXFRAME frame, Vector3 *min, Vector3 *max)
{
LPD3DXMESHCONTAINER meshContainer = frame->pMeshContainer;
// If this Frame contains a mesh...
while (meshContainer)
{
BYTE* pData = NULL;
meshContainer->MeshData.pMesh->LockVertexBuffer(D3DLOCK_READONLY, (void**)&pData);
// Compute the Min and Max values for this frames mesh
Vector3 tempMin, tempMax;
D3DXComputeBoundingBox((Vector3*)pData, meshContainer->MeshData.pMesh->GetNumVertices(), D3DXGetFVFVertexSize(meshContainer->MeshData.pMesh->GetFVF()), &tempMin, &tempMax);
meshContainer->MeshData.pMesh->UnlockVertexBuffer();

// If the min/max values are lower/greater then the current stored values, update them.
min->x = min(min->x, tempMin.x);
min->y = min(min->y, tempMin.y);
min->z = min(min->z, tempMin.z);
max->x = max(max->x, tempMax.x);
max->y = max(max->y, tempMax.y);
max->z = max(max->z, tempMax.z);

meshContainer = meshContainer->pNextMeshContainer;
}

// Recurse for sibblings
if (frame->pFrameSibling != NULL)
FrameCalculateBoundingBox(frame->pFrameSibling, min, max);

// Recurse for children
if (frame->pFrameFirstChild != NULL)
FrameCalculateBoundingBox(frame->pFrameFirstChild, min, max);
}


(Just to note the above code isn't handling the axis alignment thats done every frame created from this initial box dependant on the rotation/scaling/positioning of the model in question.)

The bounding Sphere was easy enough with a call to D3DXFrameCalculateBoundingSphere()
However I'm fairly sure there is no such function implemented for Bounding Boxes (I could be wrong).

Thanks in advance for any help.
(edited post to place code in source brackets instead of code)

[Edited by - liamf1986 on October 28, 2010 11:49:46 AM]

Multi texture terrain

21 July 2010 - 05:14 AM

Hellos,

I'm working on a multi texture terrain in C++ with Direct x.
I did in it XNA about a year ago following this tutorial http://www.riemers.net/eng/Tutorials/XNA/Csharp/series4.php
and this is a port of the final result.

I'm using 4 textures, a different texture should be shown dependant on the height of the vertex being processed. Its not working however the weighting for texture 3 and 4 seems to be getting incorrect information within the shader.

I'm fairly certain the problem is with my vertex declaration leading to information being passed to the shader incorrectly. I just can't seem to isolate the error.

I'm using the following Vertex declaration,
#define FVF_MULTITEXLITVERTEX (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1 | D3DFVF_TEX2)
typedef struct _MULTITEXLITVERTEX
{
Vector3 vecPosition;
Vector3 vecNormal;
Vector2 vecTexCoords;
Vector4 vecTextureWeights;
} MULTITEXLITVERTEX;


and below is the vertex shader code,
MTVertexToPixel MultiTexturedVS( float4 inPos : POSITION, float3 inNormal: NORMAL, float2 inTexCoords: TEXCOORD0, float4 inTexWeights: TEXCOORD1)
{
// unimportant code hidden
Output.TextureWeights = inTexWeights;

return Output;
}


and finally my redering code,

void Terrain::Render(Camera cam)
{
// Set terrains VertexBuffer to the Graphics card
Engine_Settings.D3D_Device->SetStreamSource(0, terrainVertexBuffer, 0, sizeof(MULTITEXLITVERTEX));
Engine_Settings.D3D_Device->SetFVF(FVF_MULTITEXLITVERTEX);
// Set the terrains IndexBuffer to the Graphics card
Engine_Settings.D3D_Device->SetIndices(terrainIndexBuffer);

terrainEffect.Begin();
for (unsigned short i = 0; i < terrainEffect.GetPasses(); i++)
{
terrainEffect.BeginPass(i);
Engine_Settings.D3D_Device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, iNumVertices, 0, (map.GetWidth()-1)*(map.GetHeight()-1)*2);
terrainEffect.EndPass();
}
terrainEffect.End();
}


Any help is greatly appreciated thanks in advance ^^

mesh vertex decleration and shader confusion

23 September 2009 - 10:58 AM

Hello, I'm trying to integrate a shader i'v been using in XNA into my DirectX project. Each render i get the following warning, Direct3D9: (WARN) :Vertex shader function usage (D3DDECLUSAGE_TANGENT, 0) does not have corresponding usage in the current vertex declaration Which i think means i'm not sending tangent information along with my vertex data. I'm using a mesh loaded from an x file and i'm not sure how to add the tangent information to the FVF. So far i have the following,
// Make sure there is normal and tangent information.
    if(!(mesh->GetFVF() & D3DFVF_NORMAL))
    {
        LPMesh tempMesh;
        if (FAILED(mesh->CloneMeshFVF(mesh->GetOptions(),
									  mesh->GetFVF() | D3DFVF_NORMAL | D3DFVF_TEX2 | D3DFVF_TEXCOORDSIZE3(1),
									  Engine_Settings.D3D_Device, &tempMesh)))
		{
			std::string msg = "CloneMeshFVF() failed on " + filename + ".\n";
			MessageBox(NULL, msg.c_str(), "Mesh Loading", MB_OK);
			Engine_Settings.EngineContinue = false;
			return;
		}
        if (FAILED(D3DXComputeNormals(tempMesh, NULL)))
		{
			std::string msg = "D3DXComputeNormals() failed on " + filename + ".\n";
			MessageBox(NULL, msg.c_str(), "Mesh Loading", MB_OK);
			Engine_Settings.EngineContinue = false;
			return;
		}
		if (FAILED(D3DXComputeTangent(tempMesh, 0, 0, D3DX_DEFAULT, TRUE, NULL)))
		{
			std::string msg = "D3DXComputeTangent() failed on " + filename + ".\n";
			MessageBox(NULL, msg.c_str(), "Mesh Loading", MB_OK);
			Engine_Settings.EngineContinue = false;
			return;
		}

		if (mesh != NULL)
		{
			mesh->Release();
			mesh = NULL;
		}
        mesh = tempMesh;
    }
	else // If there are normals just add tangent information.
	{
		LPMesh tempMesh;
        if (FAILED(mesh->CloneMeshFVF(mesh->GetOptions(),
									  mesh->GetFVF() | D3DFVF_TEX2 | D3DFVF_TEXCOORDSIZE3(1),
									  Engine_Settings.D3D_Device, &tempMesh)))
		{
			std::string msg = "CloneMeshFVF() failed on " + filename + ".\n";
			MessageBox(NULL, msg.c_str(), "Mesh Loading", MB_OK);
			Engine_Settings.EngineContinue = false;
			return;
		}
		if (FAILED(D3DXComputeTangent(tempMesh, 0, 0, D3DX_DEFAULT, TRUE, NULL)))
		{
			std::string msg = "D3DXComputeTangent() failed on " + filename + ".\n";
			MessageBox(NULL, msg.c_str(), "Mesh Loading", MB_OK);
			Engine_Settings.EngineContinue = false;
			return;
		}

		if (mesh != NULL)
		{
			mesh->Release();
			mesh = NULL;
		}
        mesh = tempMesh;
	}


The D3DXComputeTangent() function fails everytime. This is the struct the shader expects,
struct VS_IN
{
	float4 Position : POSITION;
	float2 TexCoord : TEXCOORD0;
	float3 Normal : NORMAL;
	float3 Tangent : TANGENT;
};


anyhelp on adding tangent information to FVF or the correct use of the D3DXComputeTangent() function would be greatly appreciated.

PARTNERS