• Advertisement
Sign in to follow this  

Sound question

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

Hello! I have to get the Sound output of my Music. This means something like AudioLeft=MyBuffer[0][SamplesPlayed]; AudioRight=MyBuffer[1][SamplesPlayed]; or so. (first [] means the channes, second [] the AudioSamples in the buffer) Currently I've got only one buffer for everything. I use the Wav-Loading code of the XAudio2 documentation:
HRESULT WAudio::CreateAudioFromFile(LPWSTR Path)
{
	

#ifdef _XBOX
	CHAR AP[MAX_PATH];
	strcpy(&AP,"game:\\");
	//strcat(&AP,
	char * strFileName = "game:\\media\\MusicMono.wav";
#else
	WCHAR AP[MAX_PATH];
	wcscpy(LPS AP,Path);
	//TCHAR * strFileName = _TEXT("media\\MusicMono.wav");
#endif
	// Open the file
	HANDLE hFile = CreateFile(
		LPS AP,
		GENERIC_READ,
		FILE_SHARE_READ,
		NULL,
		OPEN_EXISTING,
		0,
		NULL );

	if( INVALID_HANDLE_VALUE == hFile )
		return HRESULT_FROM_WIN32( GetLastError() );

	if( INVALID_SET_FILE_POINTER == SetFilePointer( hFile, 0, NULL, FILE_BEGIN ) )
		return HRESULT_FROM_WIN32( GetLastError() );


	DWORD dwChunkSize;
	DWORD dwChunkPosition;
	//check the file type, should be fourccWAVE or 'XWMA'
	FindChunk(hFile,fourccRIFF,dwChunkSize, dwChunkPosition );
	DWORD filetype;
	ReadChunkData(hFile,&filetype,sizeof(DWORD),dwChunkPosition);
	if (filetype != fourccWAVE)
		return S_FALSE;

	FindChunk(hFile,fourccFMT, dwChunkSize, dwChunkPosition );
	ReadChunkData(hFile, &wfx, dwChunkSize, dwChunkPosition );

	//fill out the audio data buffer with the contents of the fourccDATA chunk
	FindChunk(hFile,fourccDATA,dwChunkSize, dwChunkPosition );
	BYTE * pDataBuffer = new BYTE[dwChunkSize];
	ReadChunkData(hFile, pDataBuffer, dwChunkSize, dwChunkPosition);

	AudioData=pDataBuffer;
	AudioSize=dwChunkSize;

	buffer.AudioBytes = dwChunkSize;  //buffer containing audio data
	buffer.pAudioData = pDataBuffer;  //size of the audio buffer in bytes
	buffer.Flags = XAUDIO2_END_OF_STREAM; // tell the source voice not to expect any data after this buffer



}

My goal is to make a music visualization program, and this seems to be the last thing missing. I can allready calculate a FFT, but the input seems to be wrong. (because I just pass the whole buffer) Can you help me?

Share this post


Link to post
Share on other sites
Advertisement
Not quite sure I understand your question. What exactly do you need help with?

Most of the FFTs that I have seen (including the FFT functions in XAudio2) expect the data provided to be mono floating point data. This is a fairly trivial conversion if that is what you are looking for.

Share this post


Link to post
Share on other sites
Ok! I solved the problem now, but I've got a new one -> New thread.

Share this post


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

  • Advertisement