Switch to using "opus" and add support for windows
This commit is contained in:
Generated
+37
-31
@@ -104,26 +104,6 @@ version = "1.0.98"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487"
|
||||
|
||||
[[package]]
|
||||
name = "audiopus"
|
||||
version = "0.3.0-rc.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ab55eb0e56d7c6de3d59f544e5db122d7725ec33be6a276ee8241f3be6473955"
|
||||
dependencies = [
|
||||
"audiopus_sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "audiopus_sys"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "62314a1546a2064e033665d658e88c620a62904be945f8147e6b16c3db9f8651"
|
||||
dependencies = [
|
||||
"cmake",
|
||||
"log",
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.5.0"
|
||||
@@ -165,10 +145,11 @@ checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.2.32"
|
||||
version = "1.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2352e5597e9c544d5e6d9c95190d5d27738ade584fa8db0a16e130e5c2b5296e"
|
||||
checksum = "f360145194ee8e21db5ee7f3fcd4fe52210864c75c985dae33218202c8bbe040"
|
||||
dependencies = [
|
||||
"find-msvc-tools",
|
||||
"shlex",
|
||||
]
|
||||
|
||||
@@ -240,9 +221,9 @@ checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675"
|
||||
|
||||
[[package]]
|
||||
name = "cmake"
|
||||
version = "0.1.54"
|
||||
version = "0.1.58"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e7caa3f9de89ddbe2c607f4101924c5abec803763ae9534e4f4d7d8f84aa81f0"
|
||||
checksum = "c0f78a02292a74a88ac736019ab962ece0bc380e3f977bf72e376c5d78ff0678"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
@@ -394,6 +375,12 @@ version = "2.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
|
||||
|
||||
[[package]]
|
||||
name = "find-msvc-tools"
|
||||
version = "0.1.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aedcfb3409746eddb02b9e19ebda1c3394f759a152e48ee875a0844d1b955484"
|
||||
|
||||
[[package]]
|
||||
name = "fixedbitset"
|
||||
version = "0.5.7"
|
||||
@@ -877,6 +864,24 @@ version = "1.70.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad"
|
||||
|
||||
[[package]]
|
||||
name = "opus"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "33718946cc77d4032911d4efe03a66dbcbfbd2bb16c3da06aaeadcc637c32216"
|
||||
dependencies = [
|
||||
"opusic-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "opusic-sys"
|
||||
version = "0.7.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c9d1ecdf206421bc74343ab3bb2f30ad2abbfee41fa341f7181fecbaf957769a"
|
||||
dependencies = [
|
||||
"cmake",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "petgraph"
|
||||
version = "0.7.1"
|
||||
@@ -944,9 +949,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "prost"
|
||||
version = "0.14.1"
|
||||
version = "0.14.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7231bd9b3d3d33c86b58adbac74b5ec0ad9f496b19d22801d773636feaa95f3d"
|
||||
checksum = "528ac67416ff8646872a3c02cad9cc4ee5dc9f9540c9b10771855c95cb2e5ae1"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"prost-derive",
|
||||
@@ -974,9 +979,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "prost-derive"
|
||||
version = "0.14.1"
|
||||
version = "0.14.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9120690fafc389a67ba3803df527d0ec9cbbc9cc45e4cc20b332996dfb672425"
|
||||
checksum = "b570b25f7617e43d59005d0990ccb79e950a423952cea19671b7a876da390adf"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"itertools",
|
||||
@@ -1119,9 +1124,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "1.3.0"
|
||||
version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
|
||||
|
||||
[[package]]
|
||||
name = "simd_cesu8"
|
||||
@@ -1167,7 +1172,6 @@ name = "tap"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"audiopus",
|
||||
"chrono",
|
||||
"circular-buffer",
|
||||
"clap",
|
||||
@@ -1175,6 +1179,8 @@ dependencies = [
|
||||
"env_logger",
|
||||
"hound",
|
||||
"log",
|
||||
"opus",
|
||||
"opusic-sys",
|
||||
"prost",
|
||||
"tap-interface",
|
||||
"thiserror 2.0.12",
|
||||
|
||||
+8
-1
@@ -9,10 +9,17 @@ clap = { version = "4.5.43", features = ["derive"] }
|
||||
anyhow = "1.0.98"
|
||||
log = "0.4.27"
|
||||
env_logger = "0.11.8"
|
||||
audiopus = "0.3.0-rc.0"
|
||||
opus= { version="0.4.0" }
|
||||
thiserror = "2.0.12"
|
||||
circular-buffer = "2.0.1"
|
||||
chrono = "0.4.41"
|
||||
hound = "3.5.1"
|
||||
tap-interface = {version = "0.1.0", registry = "ahines"}
|
||||
prost = "0.14.1"
|
||||
opusic-sys = { version = "0.7.5", features = ["bundled", "no-stack-protector", "no-hardening", "no-fortify-source"] }
|
||||
|
||||
[workspace.metadata.cross.target.x86_64-pc-windows-gnu]
|
||||
pre-build = [
|
||||
"apt-get update && apt-get --assume-yes install protobuf-compiler",
|
||||
"export OPUS_LIB_STATIC=true"
|
||||
]
|
||||
|
||||
+3
-8
@@ -1,11 +1,9 @@
|
||||
use crate::udp_connection::OpusUdpConnection;
|
||||
use crate::util::{SAMPLE_RATE, SAMPLE_RATE_RAW, STEREO_FRAME_SIZE, TAP_PACKET_MAX_DATA_LEN};
|
||||
use anyhow::Error;
|
||||
use audiopus::coder::Decoder;
|
||||
use audiopus::packet::Packet;
|
||||
use audiopus::{Channels, MutSignals};
|
||||
use chrono::Utc;
|
||||
use log::{error, warn};
|
||||
use opus::{Channels, Decoder};
|
||||
use prost::Message;
|
||||
use std::io::{ErrorKind, Read};
|
||||
use std::net::SocketAddr;
|
||||
@@ -33,7 +31,6 @@ pub fn record(addr: SocketAddr, output_path: &Path, duration_ms: u64) -> Result<
|
||||
while std::time::Instant::now() < deadline {
|
||||
let mut packet = vec![0; TAP_PACKET_MAX_DATA_LEN];
|
||||
let mut output_buffer = vec![0.0; STEREO_FRAME_SIZE];
|
||||
let signals = MutSignals::try_from(&mut output_buffer)?;
|
||||
|
||||
let new_packet = match udp_connection.read(&mut packet) {
|
||||
Ok(data_len) => Some(&packet[0..data_len]),
|
||||
@@ -67,11 +64,9 @@ pub fn record(addr: SocketAddr, output_path: &Path, duration_ms: u64) -> Result<
|
||||
|
||||
(seq_count, _) = tap_message.seq.overflowing_add(1);
|
||||
|
||||
let packet = Packet::try_from(&tap_message.audio_data)?;
|
||||
|
||||
decoder.decode_float(Some(packet), signals, false)?
|
||||
decoder.decode_float(&packet, &mut output_buffer, false)?
|
||||
} else {
|
||||
decoder.decode_float(None, signals, false)?
|
||||
decoder.decode_float(&[], &mut output_buffer, false)?
|
||||
} * 2;
|
||||
|
||||
for samples in output_buffer[..data_size].chunks(2) {
|
||||
|
||||
+2
-3
@@ -1,13 +1,12 @@
|
||||
use std::io::{stdin, Read};
|
||||
use crate::tx_thread::TxThread;
|
||||
use crate::udp_connection::OpusUdpConnection;
|
||||
use crate::util::{SAMPLE_RATE, SAMPLE_RATE_RAW, STEREO_FRAME_SIZE, ThreadMessage};
|
||||
use anyhow::Error;
|
||||
use audiopus::coder::Encoder;
|
||||
use audiopus::{Application, Bitrate, Channels, Signal};
|
||||
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
|
||||
use cpal::{BufferSize, FromSample, Host, Sample, SampleRate, StreamConfig};
|
||||
use log::{error, info};
|
||||
use opus::{Application, Bitrate, Channels, Encoder, Signal};
|
||||
use std::io::{Read, stdin};
|
||||
use std::net::SocketAddr;
|
||||
use std::sync::mpsc::{Sender, channel};
|
||||
use std::thread;
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
use crate::udp_connection::OpusUdpConnection;
|
||||
use crate::util::STEREO_FRAME_SIZE;
|
||||
use crate::util::{CIRC_BUFFER_SIZE, TAP_PACKET_MAX_DATA_LEN, ThreadMessage};
|
||||
use audiopus::coder::Encoder;
|
||||
use chrono::Utc;
|
||||
use circular_buffer::FixedCircularBuffer;
|
||||
use log::{error, info, warn};
|
||||
use opus::Encoder;
|
||||
use prost::Message;
|
||||
use std::io::Write;
|
||||
use std::sync::mpsc::{Receiver, RecvError};
|
||||
@@ -18,7 +18,7 @@ pub enum Error {
|
||||
#[error("IO error on offload: {0}")]
|
||||
IoFailure(#[from] std::io::Error),
|
||||
#[error("Encode error: {0}")]
|
||||
EncodeFailure(#[from] audiopus::Error),
|
||||
EncodeFailure(#[from] opus::Error),
|
||||
}
|
||||
|
||||
pub struct TxThread {
|
||||
|
||||
+3
-2
@@ -1,7 +1,8 @@
|
||||
use audiopus::SampleRate;
|
||||
use cpal::SampleRate;
|
||||
|
||||
pub const SAMPLE_RATE: SampleRate = SampleRate::Hz48000;
|
||||
pub const SAMPLE_RATE_RAW: usize = 48_000;
|
||||
|
||||
pub const SAMPLE_RATE: SampleRate = SAMPLE_RATE_RAW as u32;
|
||||
pub const AUDIO_FRAME_RATE: usize = 50;
|
||||
pub const MONO_FRAME_SIZE: usize = SAMPLE_RATE_RAW / AUDIO_FRAME_RATE;
|
||||
pub const STEREO_FRAME_SIZE: usize = 2 * MONO_FRAME_SIZE;
|
||||
|
||||
Reference in New Issue
Block a user