Skip to content

Commit 789fad1

Browse files
committed
yes
1 parent 7b23c39 commit 789fad1

File tree

7 files changed

+89
-49
lines changed

7 files changed

+89
-49
lines changed

Cargo.lock

Lines changed: 46 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "silence-core"
3-
version = "0.1.9"
3+
version = "0.1.11"
44
edition = "2021"
55
description = "Core audio I/O abstractions for the silence crate."
66
license = "Apache-2.0"
@@ -41,3 +41,4 @@ opus = {version = "0.3.0", optional = true}
4141
ravif = {version = "0.11.11", optional = true}
4242
opencv = {version = "0.93.4", optional = true}
4343
image = {version = "0.25.5", optional = true}
44+
deepsize = "0.2.0"

src/io/mod.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,30 @@ pub fn get_audio_device(device: Host) -> HostDevice {
6161
output: device.default_output_device(),
6262
}
6363
}
64+
65+
/// Shows the encoder type of the packet.
66+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
67+
#[derive(Debug, deepsize::DeepSizeOf)]
68+
pub enum EncoderType {
69+
/// The encoder of this packet was [`opus`].
70+
/// The inner value contains whether.
71+
Opus(bool),
72+
}
73+
74+
/// The encoded sound packet.
75+
/// Contains useful information about the encoded packet.
76+
#[derive(Debug, deepsize::DeepSizeOf)]
77+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
78+
pub struct SoundPacket {
79+
/// The Encoder's type which this [`SoundPacket`] got encoded with.
80+
pub encoder_type: EncoderType,
81+
/// The sample rate of the encoded packet.
82+
pub sample_rate: u32,
83+
/// The channel count of the encoded packet.
84+
pub channels: u32,
85+
/// The bytes of the encoded sound packet.
86+
pub bytes: Vec<u8>,
87+
/// The count of samples per frame.
88+
pub samples_per_frame: u64,
89+
}
90+

src/opus/decode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use anyhow::Result;
44
use opus::Decoder;
55

6-
use super::SoundPacket;
6+
use crate::io::SoundPacket;
77

88
///
99
/// Create an [`opus`] decoder.
@@ -59,7 +59,7 @@ pub fn decode_samples_opus(
5959
let mut samples = vec![];
6060

6161
for sound_packet in sound_packets {
62-
let super::encode::EncoderType::Opus(fec) = sound_packet.encoder_type;
62+
let crate::io::EncoderType::Opus(fec) = sound_packet.encoder_type;
6363

6464
let decoded_samples = decode_sample_set_size_opus(&mut decoder, sound_packet, fec)?;
6565

src/opus/encode.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
33
use opus::{Channels, Encoder};
44

5-
use super::SoundPacket;
5+
use crate::io::EncoderType;
6+
7+
use crate::io::SoundPacket;
68

79
///
810
/// Create an [`opus`] encoder.
@@ -99,13 +101,4 @@ pub fn encode_samples_opus(
99101
}
100102

101103
Ok(sound_packets)
102-
}
103-
104-
/// Shows the encoder type of the packet.
105-
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
106-
#[derive(Debug)]
107-
pub enum EncoderType {
108-
/// The encoder of this packet was [`opus`].
109-
/// The inner value contains whether.
110-
Opus(bool),
111-
}
104+
}

src/opus/mod.rs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,7 @@
11
//! This feature allows opus encoding and decoding for efficient byte transfer, while not sacirifising audio quality.
22
3-
use encode::EncoderType;
43
pub mod decode;
54
pub mod encode;
65

76
/// Re-export the opus crate.
8-
pub use opus;
9-
10-
/// The encoded sound packet.
11-
/// Contains useful information about the encoded packet.
12-
#[derive(Debug)]
13-
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
14-
pub struct SoundPacket {
15-
/// The Encoder's type which this [`SoundPacket`] got encoded with.
16-
pub encoder_type: EncoderType,
17-
/// The sample rate of the encoded packet.
18-
pub sample_rate: u32,
19-
/// The channel count of the encoded packet.
20-
pub channels: u32,
21-
/// The bytes of the encoded sound packet.
22-
pub bytes: Vec<u8>,
23-
/// The count of bytes of the packet.
24-
pub samples_per_frame: u64,
25-
}
7+
pub use opus;

src/tests.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ mod tests {
66
use std::{collections::VecDeque, fs, thread::sleep, time::Duration};
77

88
use cpal::traits::{DeviceTrait, StreamTrait};
9+
use deepsize::DeepSizeOf;
910
use opencv::videoio::{CAP_ANY, CAP_MSMF};
1011
use opus::Channels;
1112
use ravif::Encoder;
@@ -99,7 +100,7 @@ mod tests {
99100
record_audio_with_interrupt(input_device, receiver, err_callback, config.into())
100101
.unwrap();
101102

102-
sleep(Duration::from_secs(3));
103+
sleep(Duration::from_millis(30));
103104

104105
sender.send(()).unwrap();
105106

@@ -125,14 +126,18 @@ mod tests {
125126
)
126127
.unwrap();
127128

128-
let sound_packets: Vec<crate::opus::SoundPacket> = encode_samples_opus(encoder, &Into::<Vec<f32>>::into(sample), 20, channels).unwrap();
129+
let sound_packets: Vec<crate::io::SoundPacket> = encode_samples_opus(encoder, &Into::<Vec<f32>>::into(sample), 20, channels).unwrap();
129130

130131
let decoder = create_opus_decoder(48000).unwrap();
131132

133+
dbg!(sound_packets.deep_size_of());
134+
132135
let decoded_buf = decode_samples_opus(decoder, sound_packets).unwrap();
133136

134137
let err_callback = |err| eprintln!("an error occurred on stream: {}", err);
135138

139+
sleep(Duration::from_secs(1));
140+
136141
let stream = stream_audio(
137142
audio_device.output.unwrap(),
138143
err_callback,

0 commit comments

Comments
 (0)