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
RReactiflux
Created by nullptr on 9/17/2023 in #react-forum
hot-reload for class-based windowing system
hi! i'm working on a proof-of-concept windowing system in react. you can see the current dev build at https://nota-robot.com. the window system is class based, with a WindowManager class managing the windows and a Window class which acts as a singular window. it works based off ids, and you create windows like so:
const window = new Window("title", <WindowContents />);
const window = new Window("title", <WindowContents />);
however, the component passed to it doesn't hot-reload like the rest of the page does. i need changes to propogate from the component to the actual site so that i can quickly block out designs without closing and re-opening windows. why might it not be hot reloading? i'm using vite and tsx
2 replies