You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have developed a class in VB.NET that dynamically adjusts the gain of an audio signal to maintain a consistent volume level. It has proven to be very effective for my needs, so I decided to convert it to C#. My knowledge of C# is limited, so any improvements or feedback are welcome. I believe this class could be a valuable addition to the NAudio library.
using System;
using NAudio.Wave;
namespace AudioPlaybackExample
{
class Program
{
static void Main(string[] args)
{
// File path to audio
string audioFilePath = "path_to_your_audio_file.wav";
using (var audioFileReader = new AudioFileReader(audioFilePath))
{
// Convert audio to 32 bits (SampleChannel)
var sampleChannel = new SampleChannel(audioFileReader, true);
// Create instance for AutoGainSampleProvider with parameters
var autoGain = new AutoGainSampleProvider(
sampleChannel,
gainFactor: 1.0f,
targetLevel: 0.1995f,
maxGain: 2.0f,
adjustmentSpeed: 0.00001f,
gateThreshold: 0.01f,
freezeThreshold: 0.05f,
attack: 0.001f,
release: 0.0005f,
ratio: 1.0f,
isEnabled: true
);
// Use WaveOutEvent for play
using (var waveOut = new WaveOutEvent())
{
waveOut.Init(autoGain);
waveOut.Play();
// Wait for end
while (waveOut.PlaybackState == PlaybackState.Playing)
{
System.Threading.Thread.Sleep(100);
}
}
}
}
}
}
I apologize if there are any errors in the code. I used AI to convert it from VB.NET to C#. If needed, I have the original code written in VB.NET.
Feel free to reach out if you have any questions or suggestions for improvement.
The text was updated successfully, but these errors were encountered:
I have developed a class in VB.NET that dynamically adjusts the gain of an audio signal to maintain a consistent volume level. It has proven to be very effective for my needs, so I decided to convert it to C#. My knowledge of C# is limited, so any improvements or feedback are welcome. I believe this class could be a valuable addition to the NAudio library.
A code example (generated by IA)
I apologize if there are any errors in the code. I used AI to convert it from VB.NET to C#. If needed, I have the original code written in VB.NET.
Feel free to reach out if you have any questions or suggestions for improvement.
The text was updated successfully, but these errors were encountered: