nullptr
nullptr
Explore posts from servers
CC#
Created by nullptr on 10/4/2024 in #help
✅ remove dotted border around win32 control in wpf?
No description
4 replies
CC#
Created by nullptr on 10/3/2024 in #help
win32 island in wpf application has #f0f0f0 background colour
No description
3 replies
CC#
Created by nullptr on 9/25/2024 in #help
artifacted playback using `NAudio` with multiple raw pcm streams
hello there! i'm trying to implement voice chat into a custom discord library i'm writing. everything works great but the sound quality dips heavily if 2 or more users are speaking at once. you can see my player class below:
public class NAudioPlayer : IPlayer
{
private readonly ConcurrentDictionary<uint, BufferedWaveProvider> _waveProviders = new();
private readonly MixingSampleProvider _mixer;
private readonly WaveOutEvent _waveOut;
private readonly WaveFormat _format = new(48000, 16, 2);

public NAudioPlayer()
{
_mixer = new MixingSampleProvider(WaveFormat.CreateIeeeFloatWaveFormat(48000, 2));
_mixer.ReadFully = true;
_waveOut = new WaveOutEvent();
_waveOut.Init(_mixer);
_waveOut.Play();
}

public void AddSamples(byte[] pcmData, int pcmLength, uint ssrc)
{
if (!_waveProviders.TryGetValue(ssrc, out var waveProvider))
{
waveProvider = new BufferedWaveProvider(_format)
{
DiscardOnBufferOverflow = true
};
var sampleProvider = waveProvider.ToSampleProvider();
_waveProviders.TryAdd(ssrc, waveProvider);
_mixer.AddMixerInput(sampleProvider);
}

_waveProviders[ssrc].AddSamples(pcmData, 0, pcmLength);
}
}
public class NAudioPlayer : IPlayer
{
private readonly ConcurrentDictionary<uint, BufferedWaveProvider> _waveProviders = new();
private readonly MixingSampleProvider _mixer;
private readonly WaveOutEvent _waveOut;
private readonly WaveFormat _format = new(48000, 16, 2);

public NAudioPlayer()
{
_mixer = new MixingSampleProvider(WaveFormat.CreateIeeeFloatWaveFormat(48000, 2));
_mixer.ReadFully = true;
_waveOut = new WaveOutEvent();
_waveOut.Init(_mixer);
_waveOut.Play();
}

public void AddSamples(byte[] pcmData, int pcmLength, uint ssrc)
{
if (!_waveProviders.TryGetValue(ssrc, out var waveProvider))
{
waveProvider = new BufferedWaveProvider(_format)
{
DiscardOnBufferOverflow = true
};
var sampleProvider = waveProvider.ToSampleProvider();
_waveProviders.TryAdd(ssrc, waveProvider);
_mixer.AddMixerInput(sampleProvider);
}

_waveProviders[ssrc].AddSamples(pcmData, 0, pcmLength);
}
}
there is only one NAudioPlayer initialized for the entire voice session, but it uses ssrcs sent by discord's voice gateway and udp servers to split them into different streams and mix them together. however, this mixing seems to do absolutely nothing; it sounds exactly the same if i just add samples to the same wave provider for every user. what am i doing wrong?
1 replies
CC#
Created by nullptr on 6/25/2024 in #help
how can i speed up this transparent image rendering in winforms?
hello! i'll be frank; i found this code on Stack Overflow and it goes far over my head, i just need a way to layer transparent images. this is the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Aerochat.Forms
{
class TransparentPictureBox : PictureBox
{
public TransparentPictureBox()
{
this.BackColor = Color.Transparent;
}
protected override void OnPaint(PaintEventArgs e)
{
if (Parent != null && this.BackColor == Color.Transparent)
{
using (var bmp = new Bitmap(Parent.Width, Parent.Height))
{
Parent.Controls.Cast<Control>()
.Where(c => Parent.Controls.GetChildIndex(c) > Parent.Controls.GetChildIndex(this))
.Where(c => c.Bounds.IntersectsWith(this.Bounds))
.OrderByDescending(c => Parent.Controls.GetChildIndex(c))
.ToList()
.ForEach(c => c.DrawToBitmap(bmp, c.Bounds));

e.Graphics.DrawImage(bmp, -Left, -Top);

}
}
base.OnPaint(e);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Aerochat.Forms
{
class TransparentPictureBox : PictureBox
{
public TransparentPictureBox()
{
this.BackColor = Color.Transparent;
}
protected override void OnPaint(PaintEventArgs e)
{
if (Parent != null && this.BackColor == Color.Transparent)
{
using (var bmp = new Bitmap(Parent.Width, Parent.Height))
{
Parent.Controls.Cast<Control>()
.Where(c => Parent.Controls.GetChildIndex(c) > Parent.Controls.GetChildIndex(this))
.Where(c => c.Bounds.IntersectsWith(this.Bounds))
.OrderByDescending(c => Parent.Controls.GetChildIndex(c))
.ToList()
.ForEach(c => c.DrawToBitmap(bmp, c.Bounds));

e.Graphics.DrawImage(bmp, -Left, -Top);

}
}
base.OnPaint(e);
}
}
}
i seriously don't understand what its doing, nor why it's so slow, nor why this works but the regular PictureBox doesn't with layered transparent images. there are only a few of them on the form..
24 replies
CC#
Created by nullptr on 2/21/2024 in #help
get current windows media player info (playing or paused, current song url, etc) from a .NET app?
hello! the title really says it all, i want to be able to read the state of windows media player from c#. is that possible?
6 replies