Cannot play correctly ogg music on WP8 after decoding it with NVorbis and play with Sharpdx and XNA SoundEffect

642 Views Asked by At

I try to play a ogg music file using NVorbis to decode it, and sharpdx + XNA SoundEffect Vorbis decoder seems to work as the informations (channels, duration, SampleRate) are fine. then I use Sharpdx to create the wave Stream that will be used to create the SoundEffect. But when I try to play it, I can recognise my sound, but there also a lot of "noise" in background and the music is distorted. I don't know what to do... thanks for help! here is my code:

            string _audioPath = "music/2test.ogg";
            NVorbis.Ogg.ContainerReader oggReader = new NVorbis.Ogg.ContainerReader(_audioPath);
            using (var vorbis = new NVorbis.VorbisReader(oggReader))
            {
                int channels = vorbis.Channels;
                int sampleRate = vorbis.SampleRate;
                var duration = vorbis.TotalTime;

                var buffer = new float[vorbis.TotalSamples];

                int count;
                count = vorbis.ReadSamples(buffer, 0, buffer.Length);
                //var byteArray = new byte[buffer.Length * 4];

                // Buffer.BlockCopy(buffer, 0, byteArray, 0, byteArray.Length);


                MemoryStream stream = new MemoryStream();
                // BinaryWriter writer = new BinaryWriter(stream);

                SharpDX.Multimedia.WaveFormat wf = new SharpDX.Multimedia.WaveFormat(sampleRate, channels);
                SharpDX.Multimedia.WavWriter w = new SharpDX.Multimedia.WavWriter(stream);

                w.Begin(wf);
                w.AppendData(buffer);
                w.End();
                stream.Position = 0;

                _SoundEffect = SoundEffect.FromStream(stream);
                _SoundEffectInstance = _SoundEffect.CreateInstance();
                _SoundEffectInstance.Play();
            }
0

There are 0 best solutions below