Fix alert tones and QC2

pull/1/head
firealarmss 11 months ago
parent f3185d5e05
commit d94242289a

@ -15,35 +15,50 @@ EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
NoVocode|Any CPU = NoVocode|Any CPU
NoVocode|x64 = NoVocode|x64
NoVocode|x86 = NoVocode|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5918329A-6374-40E2-874D-445360C89676}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5918329A-6374-40E2-874D-445360C89676}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5918329A-6374-40E2-874D-445360C89676}.Debug|x64.ActiveCfg = AmbeVocode|x64
{5918329A-6374-40E2-874D-445360C89676}.Debug|x64.Build.0 = AmbeVocode|x64
{5918329A-6374-40E2-874D-445360C89676}.Debug|x86.ActiveCfg = Debug|x86
{5918329A-6374-40E2-874D-445360C89676}.Debug|x86.Build.0 = Debug|x86
{5918329A-6374-40E2-874D-445360C89676}.NoVocode|Any CPU.ActiveCfg = NoVocode|Any CPU
{5918329A-6374-40E2-874D-445360C89676}.NoVocode|Any CPU.Build.0 = NoVocode|Any CPU
{5918329A-6374-40E2-874D-445360C89676}.NoVocode|x64.ActiveCfg = NoVocode|x64
{5918329A-6374-40E2-874D-445360C89676}.NoVocode|x64.Build.0 = NoVocode|x64
{5918329A-6374-40E2-874D-445360C89676}.NoVocode|x86.ActiveCfg = NoVocode|x86
{5918329A-6374-40E2-874D-445360C89676}.NoVocode|x86.Build.0 = NoVocode|x86
{5918329A-6374-40E2-874D-445360C89676}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5918329A-6374-40E2-874D-445360C89676}.Release|Any CPU.Build.0 = Release|Any CPU
{5918329A-6374-40E2-874D-445360C89676}.Release|x64.ActiveCfg = Release|x64
{5918329A-6374-40E2-874D-445360C89676}.Release|x64.Build.0 = Release|x64
{5918329A-6374-40E2-874D-445360C89676}.Release|x86.ActiveCfg = Release|x86
{5918329A-6374-40E2-874D-445360C89676}.Release|x86.Build.0 = Release|x86
{710D1FA8-2E0D-42CB-9174-FCD9EB7A718F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{710D1FA8-2E0D-42CB-9174-FCD9EB7A718F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{710D1FA8-2E0D-42CB-9174-FCD9EB7A718F}.Debug|x64.ActiveCfg = Debug|x64
{710D1FA8-2E0D-42CB-9174-FCD9EB7A718F}.Debug|x64.Build.0 = Debug|x64
{710D1FA8-2E0D-42CB-9174-FCD9EB7A718F}.Debug|x86.ActiveCfg = Debug|Any CPU
{710D1FA8-2E0D-42CB-9174-FCD9EB7A718F}.Debug|x86.Build.0 = Debug|Any CPU
{710D1FA8-2E0D-42CB-9174-FCD9EB7A718F}.NoVocode|Any CPU.ActiveCfg = Debug|Any CPU
{710D1FA8-2E0D-42CB-9174-FCD9EB7A718F}.NoVocode|Any CPU.Build.0 = Debug|Any CPU
{710D1FA8-2E0D-42CB-9174-FCD9EB7A718F}.NoVocode|x64.ActiveCfg = Debug|x64
{710D1FA8-2E0D-42CB-9174-FCD9EB7A718F}.NoVocode|x64.Build.0 = Debug|x64
{710D1FA8-2E0D-42CB-9174-FCD9EB7A718F}.NoVocode|x86.ActiveCfg = Debug|Any CPU
{710D1FA8-2E0D-42CB-9174-FCD9EB7A718F}.NoVocode|x86.Build.0 = Debug|Any CPU
{710D1FA8-2E0D-42CB-9174-FCD9EB7A718F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{710D1FA8-2E0D-42CB-9174-FCD9EB7A718F}.Release|Any CPU.Build.0 = Release|Any CPU
{710D1FA8-2E0D-42CB-9174-FCD9EB7A718F}.Release|x64.ActiveCfg = Release|x64
{710D1FA8-2E0D-42CB-9174-FCD9EB7A718F}.Release|x64.Build.0 = Release|x64
{710D1FA8-2E0D-42CB-9174-FCD9EB7A718F}.Release|x86.ActiveCfg = Release|Any CPU
{710D1FA8-2E0D-42CB-9174-FCD9EB7A718F}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection

@ -24,6 +24,9 @@ using System.Collections.Generic;
namespace WhackerLinkConsoleV2
{
/// <summary>
/// Class for managing
/// </summary>
public class AudioManager
{
private Dictionary<string, (WaveOutEvent waveOut, MixingSampleProvider mixer, BufferedWaveProvider buffer, GainSampleProvider gainProvider)> _talkgroupProviders;

@ -429,7 +429,7 @@ namespace WhackerLinkConsoleV2
_audioManager.AddTalkgroupStream(cpgChannel.Tgid, combinedAudio);
});
await Task.Run(async () =>
await Task.Run(() =>
{
for (int i = 0; i < totalChunks; i++)
{
@ -454,12 +454,10 @@ namespace WhackerLinkConsoleV2
};
handler.SendMessage(voicePacket.GetData());
await Task.Delay(20);
}
});
double totalDurationMs = (toneADuration + toneBDuration) * 1000 + 500;
double totalDurationMs = (toneADuration + toneBDuration) * 1000 + 250;
await Task.Delay((int)totalDurationMs);
GRP_VCH_RLS release = new GRP_VCH_RLS
@ -474,6 +472,7 @@ namespace WhackerLinkConsoleV2
Dispatcher.Invoke(() =>
{
//channel.PageState = false; // TODO: Investigate
channel.PageSelectButton.Background = Brushes.Green;
});
}
@ -487,18 +486,6 @@ namespace WhackerLinkConsoleV2
{
try
{
try
{
using (var player = new SoundPlayer(e.AlertFilePath))
{
player.Play();
}
}
catch (Exception ex)
{
MessageBox.Show($"Failed to play alert: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
foreach (ChannelBox channel in _selectedChannelsManager.GetSelectedChannels())
{
Codeplug.System system = Codeplug.GetSystemForChannel(channel.ChannelName);
@ -507,37 +494,49 @@ namespace WhackerLinkConsoleV2
if (channel.PageState)
{
List<byte[]> pcmChunks = new List<byte[]>();
WaveFileReader waveReader = null;
byte[] pcmData;
using (waveReader = new WaveFileReader(e.AlertFilePath))
using (var waveReader = new WaveFileReader(e.AlertFilePath))
{
if (waveReader.WaveFormat.Encoding != WaveFormatEncoding.Pcm)
if (waveReader.WaveFormat.Encoding != WaveFormatEncoding.Pcm ||
waveReader.WaveFormat.SampleRate != 8000 ||
waveReader.WaveFormat.BitsPerSample != 16 ||
waveReader.WaveFormat.Channels != 1)
{
MessageBox.Show("The alert tone is not in PCM format.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show("The alert tone must be PCM 16-bit, Mono, 8000Hz format.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
byte[] buffer = new byte[1600];
int bytesRead;
while ((bytesRead = waveReader.Read(buffer, 0, buffer.Length)) > 0)
using (MemoryStream ms = new MemoryStream())
{
if (bytesRead < buffer.Length)
{
byte[] finalChunk = new byte[bytesRead];
Array.Copy(buffer, finalChunk, bytesRead);
pcmChunks.Add(finalChunk);
}
else
{
pcmChunks.Add((byte[])buffer.Clone());
}
waveReader.CopyTo(ms);
pcmData = ms.ToArray();
}
}
foreach (var chunk in pcmChunks)
int chunkSize = 1600;
int totalChunks = (pcmData.Length + chunkSize - 1) / chunkSize;
if (pcmData.Length % chunkSize != 0)
{
byte[] paddedData = new byte[totalChunks * chunkSize];
Buffer.BlockCopy(pcmData, 0, paddedData, 0, pcmData.Length);
pcmData = paddedData;
}
Task.Factory.StartNew(() =>
{
_audioManager.AddTalkgroupStream(cpgChannel.Tgid, pcmData);
});
DateTime startTime = DateTime.UtcNow;
for (int i = 0; i < totalChunks; i++)
{
int offset = i * chunkSize;
byte[] chunk = new byte[chunkSize];
Buffer.BlockCopy(pcmData, offset, chunk, 0, chunkSize);
AudioPacket voicePacket = new AudioPacket
{
Data = chunk,
@ -554,10 +553,18 @@ namespace WhackerLinkConsoleV2
handler.SendMessage(voicePacket.GetData());
int chunkDurationMs = (int)(1600.0 / waveReader.WaveFormat.AverageBytesPerSecond * 1000);
await Task.Delay(chunkDurationMs);
DateTime nextPacketTime = startTime.AddMilliseconds((i + 1) * 100);
TimeSpan waitTime = nextPacketTime - DateTime.UtcNow;
if (waitTime.TotalMilliseconds > 0)
{
await Task.Delay(waitTime);
}
}
double totalDurationMs = ((double)pcmData.Length / 16000) * 1000 + 500;
await Task.Delay((int)totalDurationMs);
GRP_VCH_RLS release = new GRP_VCH_RLS
{
SrcId = system.Rid,

@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright (C) 2024 Caleb, K4PHP
* Copyright (C) 2024-2025 Caleb, K4PHP
*
*/

@ -6,6 +6,7 @@
<Nullable>disable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>

Loading…
Cancel
Save

Powered by TurnKey Linux.