change to pure rust opus lib

This commit is contained in:
2026-08-23 20:45:44 +02:00
parent 65759699eb
commit 9aa881d5cc
3 changed files with 52 additions and 41 deletions
+1 -1
View File
@@ -12,4 +12,4 @@ serde_json = "1.0.151"
tokio = { version = "1.53.1", features = ["full"] }
rand = "0.10.2"
clap = { version = "4.6.6", features = ["derive"] }
opus = "0.3.1"
ropus = "0.12.18"
+15 -10
View File
@@ -3,12 +3,12 @@ use cpal::{
Device,
traits::{DeviceTrait, HostTrait, StreamTrait},
};
use opus::{Decoder, Encoder};
use ringbuf::{
HeapRb, consumer,
traits::{Consumer, Observer, Producer, Split},
wrap::caching::Caching,
};
use ropus::{Decoder, Encoder};
use shared::{AudioStreamInfo, ResponseStatus, TcpRequest, TcpResponse, TcpResponseData};
use std::{
collections::HashMap,
@@ -157,11 +157,11 @@ async fn main() {
consumer,
);
let channels: opus::Channels = {
let channels: ropus::Channels = {
if audio_stream.channels == 1 {
opus::Channels::Mono
ropus::Channels::Mono
} else {
opus::Channels::Stereo
ropus::Channels::Stereo
}
};
@@ -333,7 +333,11 @@ async fn main() {
let mut decoder = decoder_mutex.lock().expect("failed to get encoder");
let decoded_len = decoder
.decode_float(audio_packet, &mut decoded_samples, false)
.decode_float(
audio_packet,
&mut decoded_samples,
ropus::DecodeMode::Normal,
)
.expect("failed to decode opus");
let mut active_streams_map =
@@ -477,16 +481,17 @@ async fn audio_stream_spawner(
let frames_needed = ((20.0 / 1000.0) * config.sample_rate as f32) as usize;
let mut frame_buffer = vec![0.0; frames_needed];
let channels: opus::Channels = {
let channels: ropus::Channels = {
if config.channels == 1 {
opus::Channels::Mono
ropus::Channels::Mono
} else {
opus::Channels::Stereo
ropus::Channels::Stereo
}
};
let mut opus_encoder = Encoder::new(config.sample_rate, channels, opus::Application::Voip)
.expect("falied to create opus encoder");
let mut opus_encoder = Encoder::builder(config.sample_rate, channels, ropus::Application::Voip)
.build()
.unwrap();
let mut encoded_frame_buffer = [0u8; 1024];