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
}
Sound question
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:
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?
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement