SineѶeҀҬOӶ⒉⓸⎤ᚙ▟ ▞╸
SineѶeҀҬOӶ⒉⓸⎤ᚙ▟ ▞╸
CC#
Created by SineѶeҀҬOӶ⒉⓸⎤ᚙ▟ ▞╸ on 2/19/2024 in #help
Loading shared library on Android Maui fails
So I've been following this https://learn.microsoft.com/en-us/xamarin/cross-platform/cpp/ and have got the project setup and available here https://github.com/SineVector241/OpusSharp I then packed it into a nuget library and just added it into the maui application, However when I try to run it, it fails due to [monodroid-assembly] Shared library 'libopus-share.so' not loaded, p/invoke 'opus_encoder_create' may fail. Could anyone point me in the right direction on how to fix this?
2 replies
CC#
Created by SineѶeҀҬOӶ⒉⓸⎤ᚙ▟ ▞╸ on 11/22/2022 in #help
❔ NAudio clicking sounds when playing from received packet.
Anyone have any experience with NAudio and sending the audio data over the network and playing it back. Currently I have audio being sent from the client when the microphone has data available and being played correctly through a custom server with 16kb audio at 50ms buffer. However when I play the audio I get these clicking sounds which I believe are either the waveforms not matching or when the audio stops. I have tried using a codec using G772 and ULaw but to no avail could not get it to work. What fixes are there to resolve this isssue?
public static class Audio
{
public static WaveIn waveIn = new WaveIn();
private static BufferedWaveProvider player;
private static WaveFormat wf = new WaveFormat(16000, 1);

public static void AddSamples(byte[] bytes)
{
player.AddSamples(bytes, 0, bytes.Length);
}

private static void OnDataAvailable(object? sender, WaveInEventArgs args)
{
float max = 0;
for (int index = 0; index < args.BytesRecorded; index += 2)
{
short sample = (short)((args.Buffer[index + 1] << 8) |
args.Buffer[index + 0]);
var sample32 = sample / 32768f;
if (sample32 < 0) sample32 = -sample32;
if (sample32 > max) max = sample32;
}

if (100 * max > 10)
{
Network.client.Send(new Packet() { VCAudioBuffer = args.Buffer, VCPacketDataIdentifier = PacketIdentifier.AudioStream, VCSessionKey = Network.KEY }.GetPacketDataStream());
}
}

public static void Init()
{
waveIn.BufferMilliseconds = 50;
waveIn.DeviceNumber = 0;
waveIn.WaveFormat = wf;
waveIn.DataAvailable += OnDataAvailable;
waveIn.StartRecording();
var wo = new WaveOutEvent();
BufferedWaveProvider pro = new BufferedWaveProvider(wf);
pro.DiscardOnBufferOverflow = true;
wo.Init(pro);
wo.Play();
player = pro;
}
}
public static class Audio
{
public static WaveIn waveIn = new WaveIn();
private static BufferedWaveProvider player;
private static WaveFormat wf = new WaveFormat(16000, 1);

public static void AddSamples(byte[] bytes)
{
player.AddSamples(bytes, 0, bytes.Length);
}

private static void OnDataAvailable(object? sender, WaveInEventArgs args)
{
float max = 0;
for (int index = 0; index < args.BytesRecorded; index += 2)
{
short sample = (short)((args.Buffer[index + 1] << 8) |
args.Buffer[index + 0]);
var sample32 = sample / 32768f;
if (sample32 < 0) sample32 = -sample32;
if (sample32 > max) max = sample32;
}

if (100 * max > 10)
{
Network.client.Send(new Packet() { VCAudioBuffer = args.Buffer, VCPacketDataIdentifier = PacketIdentifier.AudioStream, VCSessionKey = Network.KEY }.GetPacketDataStream());
}
}

public static void Init()
{
waveIn.BufferMilliseconds = 50;
waveIn.DeviceNumber = 0;
waveIn.WaveFormat = wf;
waveIn.DataAvailable += OnDataAvailable;
waveIn.StartRecording();
var wo = new WaveOutEvent();
BufferedWaveProvider pro = new BufferedWaveProvider(wf);
pro.DiscardOnBufferOverflow = true;
wo.Init(pro);
wo.Play();
player = pro;
}
}
4 replies