Windows 8 XAudio2和*.wav加载,HRESULT 0x88960001
我正在尝试加载一个*.wav文件,该文件是microsoft wav/8位pcm文件。我正在使用以下代码加载数据:Windows 8 XAudio2和*.wav加载,HRESULT 0x88960001,windows-8,windows-runtime,xaudio2,Windows 8,Windows Runtime,Xaudio2,我正在尝试加载一个*.wav文件,该文件是microsoft wav/8位pcm文件。我正在使用以下代码加载数据: class WavFile : public AudioSource, public LoadableObject { public: WavFile( void ) : AudioSource() , LoadableObject() { } virtual concurrency::task<void> Lo
class WavFile : public AudioSource, public LoadableObject
{
public:
WavFile( void )
: AudioSource()
, LoadableObject()
{ }
virtual concurrency::task<void> Load( Platform::String^ path )
{
buffer = nullptr;
BasicReaderWriter^ rw = ref new BasicReaderWriter();
return rw->ReadDataAsync( path ).then([this, path]( const Platform::Array<byte>^ arr ){
DWORD chunkId = 0, fileSize = 0, chunkSize = 0, extra = 0;
ByteStream stream( arr );
stream.ReadData( &chunkId, sizeof( chunkId ) );
//chunkId = stream.ReadDWORD();
char test[4];
for(unsigned int i=0; i <4; i++)
test[i] = ((char *)&chunkId)[i];
if ( chunkId != 'FFIR' ) throw ref new Platform::FailureException( L"Could not get RIFF chunk in file " + path + L", chunkId=" + chunkId.ToString() );
fileSize = stream.ReadDWORD();
if ( fileSize <= 16 ) throw ref new Platform::FailureException( L"Wave file size is too small; " + path );
extra = stream.ReadDWORD();
for(unsigned int i=0; i <4; i++)
test[i] = ((char *)&extra)[i];
if ( extra != 'EVAW' ) throw ref new Platform::FailureException( L"Could not get WAVE chunk in file " + path + L", chunkId=" + chunkId.ToString() );
bool formatChunk = false;
for(unsigned int i = 12; i < fileSize; )
{
stream.Seek( i, true );
chunkId = stream.ReadDWORD();
stream.Seek( i + 4, true );
chunkSize = stream.ReadDWORD();
if ( chunkId = ' tmf' )
{
stream.Seek( i + 8, true );
stream.ReadData( &waveFormat, sizeof( WAVEFORMATEX ) );
formatChunk = true;
break;
}
chunkSize += 8 + 1;
chunkSize &= 0xfffffffe;
stream.Seek( chunkSize, false );
i += chunkSize;
}
if ( !formatChunk ) throw ref new Platform::FailureException( L"Could not get fmt chunk in file " + path );
bool filledData = false;
for(unsigned int j=12; j < fileSize; )
{
stream.Seek( j, true );
chunkId = stream.ReadDWORD();
for(unsigned int i=0; i <4; i++)
test[i] = ((char *)&chunkId)[i];
stream.Seek( j + 4, true );
chunkSize = stream.ReadDWORD();
if ( chunkId == 'atad' )
{
byte *bufferData = new byte[chunkSize];
stream.Seek( j + 8, true );
stream.ReadData( bufferData, chunkSize );
buffer = ref new Platform::Array<byte>( bufferData, (unsigned int)chunkSize );
delete bufferData;
xbuffer.AudioBytes = chunkSize;
xbuffer.pAudioData = buffer->Data;
xbuffer.PlayBegin = 0;
xbuffer.PlayLength = 0;
filledData = true;
break;
}
chunkSize += 8 + 1;
chunkSize &= 0xfffffffe;
j += chunkSize;
}
if ( !filledData ) throw ref new Platform::FailureException( L"Could not find data chunk in file " + path );
});
}
};
我在多个地方读到,这个HRESULT是某种Windows8错误,已经一年多没有修复了。我不能接受这是一个持续的bug,更倾向于认为这是我的代码的问题。您可以签出。将XAudio2SourceVoice*的发送列表设置为空时,IXAudio2接口必须至少设置了一个主控语音。这是XAUDIO2\u E\u无效的调用,它与您传递的参数值不同。啊,所以我没有首先创建主控语音,这显然需要设置到位。我很惊讶没有更好的HRESULT值来描述这种情况。
AudioManager::AudioManager(void)
{
instance_count++;
if ( instance == nullptr )
{
DX::ThrowIfFailed( XAudio2Create( &instance, 0 ) );
}
}
AudioManager::~AudioManager(void)
{
/* Remove all the voices that were added in this audio manager */
instance_count--;
if ( instance_count == 0 )
{
HaltAudio();
instance->Release();
instance = nullptr;
}
}