Advertisement Jump to content
Sign in to follow this  
Tank202

XAudio2 and OggVorbis file library

This topic is 1742 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 there,

 

I'm trying to play audio from *.ogg format. However I'm having a bit of problem as XAudio2 won't create source voice for me. One woulp probably say that I am probably not filling whole WAVEFORMATEX structure, but I do. So I have no idea why creating source voice function fails.

 

If you have any thoughts about that I would be really happy to hear them.

 

Here is the code of my whole program code:

#include <fstream>
#include <iostream>
#include <xaudio2.h>
#include <vorbis\codec.h>
#include <vorbis\vorbisfile.h>

#pragma comment(lib, "xaudio2.lib")
#pragma comment(lib, "libvorbisfile.lib")

using namespace std;

int main()
{
	//Ogg vorbis file//                          <---- This is the booring part of the program you can skip this code
	OggVorbis_File file;
	vorbis_info* fileInfo;
	vorbis_comment* fileComment;
	int* bitstream = 0;

	ov_fopen("1.ogg", &file);
	fileInfo = ov_info(&file, -1);
	fileComment = ov_comment(&file, -1);

	char* buf = new char[2048];

	ov_read(&file, buf, 2048, 0, 2, 1, bitstream);

	cout << "BitTrack - " << file.bittrack << "\nCurrent link - " << file.current_link << "\nCurrent serial number - " << file.current_serialno
		<< "\nData offsets - " << file.dataoffsets << "\nEng - " << file.end << "\nLinks - " << file.links << "\nOffset - " << file.offset
		<< "\nPCM Lengths - " << file.pcmlengths << "\nPCM Offset - " << file.pcm_offset << "\nReady state - " << file.ready_state
		<< "\nSamptrack - " << file.samptrack << "\nSeekable - " << file.seekable << "\nSerial numbers - " << file.serialnos;

	cout << "\n\nBitrate lower - " << fileInfo->bitrate_lower << "\nBitrate nominal - " << fileInfo->bitrate_nominal
		<< "\nBitrate upper - " << fileInfo->bitrate_upper << "\nBitrate window - " << fileInfo->bitrate_window
		<< "\nChannels - " << fileInfo->channels << "\nRate - " << fileInfo->rate << "\nVersion - " << fileInfo->version;

	ofstream out("sound.txt");
	for(ogg_int64_t i = 0; i < 2048; i++)
	{
		out << buf[i];
	}
	out.close();

	//XAudio2//                                             <---- The place where the problematic code begins
	IXAudio2* engine;
	IXAudio2MasteringVoice* master;
	IXAudio2SourceVoice* source;
	WAVEFORMATEX wf;
	XAUDIO2_BUFFER buffer;

	ZeroMemory(&wf, sizeof(WAVEFORMATEX));//          <---- As you can see I initialize and fill whole struct
	wf.wFormatTag = WAVE_FORMAT_PCM;
	wf.wBitsPerSample = file.bittrack;
	wf.nAvgBytesPerSec = fileInfo->bitrate_nominal;//          <---- This bitrate is 4 times lower that *.wav
	wf.nChannels = fileInfo->channels;
	wf.nSamplesPerSec = fileInfo->rate;
	wf.nBlockAlign = (file.bittrack * fileInfo->channels) / 8;

	ZeroMemory(&buffer, sizeof(XAUDIO2_BUFFER));
	buffer.AudioBytes = file.end;
	buffer.pAudioData = (BYTE*)buf;
	buffer.Flags = XAUDIO2_END_OF_STREAM;

	XAudio2Create(&engine);
	engine->CreateMasteringVoice(&master);
	engine->CreateSourceVoice(&source, &wf);//        <---- Probably this is the place where the error occurs

	source->SubmitSourceBuffer(&buffer);// <---- Access violation happens here as source == 0(not initialized)
	source->Start();

	system("pause");
	return 0;
}

By the way checking the HRESULT says that engine->CreateSourceVoice(bla, bla, bla) is invalid... Invalid XAudio2 API call or arguments.

Edited by Tank202

Share this post


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

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!