-
-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from ciribob/micBoost
Added Microphone Boost
- Loading branch information
Showing
11 changed files
with
446 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
using Microsoft.Win32; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Ciribob.DCS.SimpleRadio.Standalone.Client | ||
{ | ||
public class AppConfiguration | ||
{ | ||
public enum RegKeys | ||
{ | ||
AUDIO_INPUT_DEVICE_ID, | ||
AUDIO_OUTPUT_DEVICE_ID, | ||
LAST_SERVER, | ||
MIC_BOOST | ||
} | ||
|
||
const string REG_PATH = "HKEY_CURRENT_USER\\SOFTWARE\\DCS-SimpleRadioStandalone"; | ||
|
||
private int _audioInputDeviceId; | ||
private int _audioOutputDeviceId; | ||
private String _lastServer; | ||
private float _micBoost; | ||
|
||
public AppConfiguration() | ||
{ | ||
try | ||
{ | ||
AudioInputDeviceId = (int)Registry.GetValue(REG_PATH, | ||
RegKeys.AUDIO_INPUT_DEVICE_ID.ToString(), | ||
0); | ||
} | ||
catch (Exception ex) | ||
{ | ||
AudioInputDeviceId = 0; | ||
} | ||
|
||
try | ||
{ | ||
AudioOutputDeviceId = (int)Registry.GetValue(REG_PATH, | ||
RegKeys.AUDIO_OUTPUT_DEVICE_ID.ToString(), | ||
0); | ||
} | ||
catch (Exception ex) | ||
{ | ||
AudioOutputDeviceId = 0; | ||
} | ||
|
||
try | ||
{ | ||
LastServer = (String)Registry.GetValue(REG_PATH, | ||
RegKeys.LAST_SERVER.ToString(), | ||
"127.0.0.1"); | ||
|
||
} | ||
catch (Exception ex) | ||
{ | ||
LastServer = "127.0.0.1"; | ||
} | ||
|
||
try | ||
{ | ||
MicBoost = float.Parse( (String)Registry.GetValue(REG_PATH, | ||
RegKeys.MIC_BOOST.ToString(), | ||
"1.0")); | ||
} | ||
catch (Exception ex) | ||
{ | ||
MicBoost = 1.0f; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
} | ||
|
||
|
||
public int AudioInputDeviceId | ||
{ | ||
get | ||
{ | ||
return _audioInputDeviceId; | ||
} | ||
set | ||
{ | ||
_audioInputDeviceId = value; | ||
|
||
Registry.SetValue(REG_PATH, | ||
RegKeys.AUDIO_INPUT_DEVICE_ID.ToString(), | ||
_audioInputDeviceId); | ||
|
||
} | ||
} | ||
|
||
public int AudioOutputDeviceId | ||
{ | ||
get | ||
{ | ||
return _audioOutputDeviceId; | ||
} | ||
set | ||
{ | ||
_audioOutputDeviceId = value; | ||
|
||
Registry.SetValue(REG_PATH, | ||
RegKeys.AUDIO_OUTPUT_DEVICE_ID.ToString(), | ||
_audioOutputDeviceId); | ||
|
||
} | ||
} | ||
public String LastServer | ||
{ | ||
get | ||
{ | ||
return _lastServer; | ||
} | ||
set | ||
{ | ||
_lastServer = value; | ||
|
||
Registry.SetValue(REG_PATH, | ||
RegKeys.LAST_SERVER.ToString(), | ||
_lastServer); | ||
|
||
} | ||
} | ||
public float MicBoost | ||
{ | ||
get | ||
{ | ||
return _micBoost; | ||
} | ||
set | ||
{ | ||
_micBoost = value; | ||
|
||
Registry.SetValue(REG_PATH, | ||
RegKeys.MIC_BOOST.ToString(), | ||
_micBoost); | ||
|
||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using Ciribob.DCS.SimpleRadio.Standalone.Client; | ||
using NAudio.Wave; | ||
using NLog; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Ciribob.DCS.SimpleRadio.Standalone.Client | ||
{ | ||
class AudioPreview | ||
{ | ||
private static Logger logger = LogManager.GetCurrentClassLogger(); | ||
WaveIn _waveIn; | ||
WaveOut _waveOut; | ||
BufferedWaveProvider _playBuffer; | ||
|
||
public VolumeWaveProvider16 Volume { get; private set; } | ||
|
||
public void StartPreview(int mic, int speakers) | ||
{ | ||
try | ||
{ | ||
_playBuffer = new BufferedWaveProvider(new NAudio.Wave.WaveFormat(24000, 16, 1)); | ||
|
||
_waveOut = new WaveOut(); | ||
_waveOut.DesiredLatency = 100; //75ms latency in output buffer | ||
_waveOut.DeviceNumber = speakers; | ||
|
||
Volume = new VolumeWaveProvider16(_playBuffer); | ||
Volume.Volume = 1.0f; // seems a good max 4.5f | ||
|
||
_waveOut.Init(Volume); | ||
_waveOut.Play(); | ||
|
||
_waveIn = new WaveIn(WaveCallbackInfo.FunctionCallback()); | ||
_waveIn.BufferMilliseconds = 60; | ||
_waveIn.DeviceNumber = mic; | ||
_waveIn.DataAvailable += _waveIn_DataAvailable; | ||
_waveIn.WaveFormat = new NAudio.Wave.WaveFormat(24000, 16, 1); | ||
|
||
_waveIn.StartRecording(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
logger.Error(ex, "Error starting audio Quitting!"); | ||
|
||
Environment.Exit(1); | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
void _waveIn_DataAvailable(object sender, WaveInEventArgs e) | ||
{ | ||
|
||
_playBuffer.AddSamples(e.Buffer, 0, e.BytesRecorded); | ||
|
||
} | ||
|
||
public void StopEncoding() | ||
{ | ||
if (_waveIn != null) | ||
{ | ||
_waveIn.StopRecording(); | ||
_waveIn.Dispose(); | ||
_waveIn = null; | ||
} | ||
|
||
if (_waveOut != null) | ||
{ | ||
_waveOut.Stop(); | ||
_waveOut.Dispose(); | ||
_waveOut = null; | ||
} | ||
|
||
if (_playBuffer != null) | ||
{ | ||
_playBuffer.ClearBuffer(); | ||
_playBuffer = null; | ||
} | ||
|
||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.