mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Corrige carregamento de SounfEffect
This commit is contained in:
parent
ce95aac19c
commit
a2e23283c6
@ -124,7 +124,7 @@ namespace xna {
|
||||
if (_byte == 'w')
|
||||
num1 = binaryReader.ReadUInt16();
|
||||
else
|
||||
return nullptr;
|
||||
throw std::runtime_error("ContentReader::PrepareStream: Bad xbn file.");
|
||||
|
||||
graphicsProfile = (num1 & XnbVersionProfileMask) >> XnbVersionProfileShift;
|
||||
bool flag = false;
|
||||
|
@ -48,7 +48,7 @@ namespace xna {
|
||||
insertRegisteredReader<Vector3Reader>("Vector3Reader");
|
||||
insertRegisteredReader<Vector4Reader>("Vector4Reader");
|
||||
insertRegisteredReader<Texture2DReader>("Texture2DReader");
|
||||
insertRegisteredReader<SoundEffect>("SoundEffectReader");
|
||||
insertRegisteredReader<SoundEffectReader>("SoundEffectReader");
|
||||
}
|
||||
|
||||
void PlatformInit::InitActivadors()
|
||||
@ -76,6 +76,6 @@ namespace xna {
|
||||
insertActivadorReader<Vector3Reader>();
|
||||
insertActivadorReader<Vector4Reader>();
|
||||
insertActivadorReader<Texture2DReader>();
|
||||
insertActivadorReader<SoundEffect>();
|
||||
insertActivadorReader<SoundEffectReader>();
|
||||
}
|
||||
}
|
@ -1,16 +1,18 @@
|
||||
#include "platform-dx/implementations.hpp"
|
||||
#include "csharp/stream.hpp"
|
||||
|
||||
using DxSoundEffect = DirectX::SoundEffect;
|
||||
|
||||
namespace xna {
|
||||
SoundEffectInstance::SoundEffectInstance() {
|
||||
impl = unew<PlatformImplementation>();
|
||||
impl = unew<PlatformImplementation>();
|
||||
}
|
||||
|
||||
SoundEffectInstance::~SoundEffectInstance() {
|
||||
impl = nullptr;
|
||||
}
|
||||
|
||||
//Remover posteriormente
|
||||
SoundEffect::SoundEffect() {
|
||||
}
|
||||
|
||||
@ -23,36 +25,64 @@ namespace xna {
|
||||
}
|
||||
|
||||
SoundEffect::SoundEffect(
|
||||
std::vector<Byte> format,
|
||||
std::vector<Byte> data,
|
||||
std::vector<Byte> const& format,
|
||||
std::vector<Byte> const& data,
|
||||
Int loopStart,
|
||||
Int loopLength,
|
||||
//We must evaluate how to use the time duration
|
||||
TimeSpan const& duration) {
|
||||
if (!AudioEngine::impl || !AudioEngine::impl->_dxAudioEngine)
|
||||
return;
|
||||
return;
|
||||
|
||||
//We expect 'format' to always be 16 bytes
|
||||
MemoryStream stream(format);
|
||||
WORD word = 0;
|
||||
DWORD dword = 0;
|
||||
|
||||
auto bWord = reinterpret_cast<Byte*>(&word);
|
||||
auto bDword = reinterpret_cast<Byte*>(&dword);
|
||||
|
||||
stream.Read(bWord, 2, 0, 2);
|
||||
auto tag = word;
|
||||
stream.Read(bWord, 2, 0, 2);
|
||||
auto channels = word;
|
||||
stream.Read(bDword, 4, 0, 4);
|
||||
auto samplesPerSec = dword;
|
||||
stream.Read(bDword, 4, 0, 4);
|
||||
auto bytesPerSec = dword;
|
||||
stream.Read(bWord, 2, 0, 2);
|
||||
auto blockAlign = word;
|
||||
stream.Read(bWord, 2, 0, 2);
|
||||
auto bitsPerSample = word;
|
||||
stream.Read(bWord, 2, 0, 2);
|
||||
auto cbSize = word;
|
||||
|
||||
auto wavData = unew<Byte[]>(data.size());
|
||||
for (size_t i = 0; i < data.size(); ++i)
|
||||
wavData[i] = data[i];
|
||||
|
||||
auto wavFormat = reinterpret_cast<WAVEFORMATEX*>(format.data());
|
||||
auto startAudio = wavData.get() + sizeof(WAVEFORMATEX);
|
||||
/*auto se = new DxSoundEffect(
|
||||
auto wfx = reinterpret_cast<WAVEFORMATEX*>(wavData.get());
|
||||
wfx->wFormatTag = tag;
|
||||
wfx->nChannels = channels;
|
||||
wfx->nSamplesPerSec = samplesPerSec;
|
||||
wfx->nAvgBytesPerSec = bytesPerSec;
|
||||
wfx->nBlockAlign = blockAlign;
|
||||
wfx->wBitsPerSample = bitsPerSample;
|
||||
wfx->cbSize = cbSize;
|
||||
|
||||
auto startAudio = wavData.get();
|
||||
|
||||
auto se = unew<DxSoundEffect>(
|
||||
AudioEngine::impl->_dxAudioEngine.get(),
|
||||
wavData,
|
||||
wavFormat,
|
||||
startAudio,
|
||||
data.size(),
|
||||
loopStart,
|
||||
loopLength);*/
|
||||
impl->_dxSoundEffect = unew<DxSoundEffect>(
|
||||
AudioEngine::impl->_dxAudioEngine.get(),
|
||||
wavData,
|
||||
wavFormat,
|
||||
wfx,
|
||||
startAudio,
|
||||
data.size(),
|
||||
loopStart,
|
||||
loopLength);
|
||||
|
||||
impl = unew<PlatformImplementation>();
|
||||
impl->_dxSoundEffect = std::move(se);
|
||||
}
|
||||
|
||||
void SoundEffect::Play() {
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "content/reader.hpp"
|
||||
#include "csharp/type.hpp"
|
||||
#include "audio/soundeffect.hpp"
|
||||
#include "csharp/timespan.hpp"
|
||||
|
||||
namespace xna {
|
||||
class SoundEffectReader : public ContentTypeReaderT<PSoundEffect> {
|
||||
@ -19,6 +20,9 @@ namespace xna {
|
||||
auto loopStart = input.ReadInt32();
|
||||
auto loopLength = input.ReadInt32();
|
||||
auto num = input.ReadInt32();
|
||||
|
||||
auto sf = snew<SoundEffect>(format, data, loopStart, loopLength, TimeSpan::FromMilliseconds((double)num));
|
||||
return sf;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -25,11 +25,12 @@ namespace xna {
|
||||
|
||||
class SoundEffect {
|
||||
public:
|
||||
//Remover posteriormente ou implementar funções de carregamento dos dados
|
||||
SoundEffect();
|
||||
SoundEffect(String const& fileName);
|
||||
SoundEffect(
|
||||
std::vector<Byte> format,
|
||||
std::vector<Byte> data,
|
||||
std::vector<Byte> const& format,
|
||||
std::vector<Byte> const& data,
|
||||
Int loopStart,
|
||||
Int loopLength,
|
||||
TimeSpan const& duration);
|
||||
|
@ -45,6 +45,9 @@ namespace xna {
|
||||
//A simplified port of the System.IO.MemoryStream.
|
||||
class MemoryStream : public Stream {
|
||||
public:
|
||||
constexpr MemoryStream(std::vector<Byte> const& bytes):
|
||||
_buffer(bytes), _length(bytes.size()){}
|
||||
|
||||
constexpr MemoryStream(Int capacity) :
|
||||
_buffer(static_cast<size_t>(capacity)),
|
||||
_length(capacity > 0 ? capacity : 0){}
|
||||
@ -79,12 +82,13 @@ namespace xna {
|
||||
virtual void Write(Byte const* buffer, Int bufferLength, Int offset, Int count) override;
|
||||
virtual void Write(std::vector<Byte> const& buffer, Int offset, Int count) override;
|
||||
virtual void WriteByte(Byte value) override;
|
||||
|
||||
|
||||
public:
|
||||
std::vector<Byte> _buffer;
|
||||
private:
|
||||
Int _position{ 0 };
|
||||
Int _origin{ 0 };
|
||||
Int _length{ 0 };
|
||||
std::vector<Byte> _buffer;
|
||||
bool _closed{ false };
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user