Skip to content

Commit

Permalink
feat(pipeline): record audio in stereo when possible
Browse files Browse the repository at this point in the history
Closes #247
  • Loading branch information
SeaDve committed Mar 1, 2024
1 parent 9112d85 commit 79f83d9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
1 change: 1 addition & 0 deletions data/io.github.seadve.Kooha.metainfo.xml.in.in
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<li>Progress is now shown when flushing the recording</li>
<li>It is now much easier to pick from frame rate options</li>
<li>Actually fixed audio from stuttering and being cut on long recordings</li>
<li>Record audio in stereo rather than mono when possible</li>
<li>Recordings are no longer deleted when flushing is cancelled</li>
<li>Significant improvements in recording performance</li>
<li>Improved preferences dialog UI</li>
Expand Down
30 changes: 22 additions & 8 deletions src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use crate::{
};

const AUDIO_SAMPLE_RATE: i32 = 48_000;
const AUDIO_N_CHANNELS: i32 = 1;

pub type Framerate = Rational32;

Expand Down Expand Up @@ -368,25 +367,40 @@ fn make_pulsesrc_bin<'a>(
) -> Result<gst::Bin> {
let bin = gst::Bin::builder().name("kooha-pulsesrc-bin").build();

let caps = gst::Caps::builder_full()
.structure(
gst::Structure::builder("audio/x-raw")
.field("rate", AUDIO_SAMPLE_RATE)
.field("channels", 2)
.build(),
)
.structure(
gst::Structure::builder("audio/x-raw")
.field("rate", AUDIO_SAMPLE_RATE)
.field("channels", 1)
.build(),
)
.build();

let audiomixer = gst::ElementFactory::make("audiomixer")
.property("latency", gst::ClockTime::from_seconds(2))
.build()?;
bin.add(&audiomixer)?;
let audiomixer_capsfilter = gst::ElementFactory::make("capsfilter")
.property("caps", &caps)
.build()?;
bin.add_many([&audiomixer, &audiomixer_capsfilter])?;
audiomixer.link(&audiomixer_capsfilter)?;

let src_pad = audiomixer.static_pad("src").unwrap();
let src_pad = audiomixer_capsfilter.static_pad("src").unwrap();
bin.add_pad(&gst::GhostPad::with_target(&src_pad)?)?;

let pulsesrc_caps = gst::Caps::builder("audio/x-raw")
.field("rate", AUDIO_SAMPLE_RATE)
.field("channels", AUDIO_N_CHANNELS)
.build();
for pulsesrc in pulsesrcs {
let audiorate = gst::ElementFactory::make("audiorate")
.property("skip-to-first", true)
.build()?;

bin.add_many([&pulsesrc, &audiorate])?;
pulsesrc.link_filtered(&audiorate, &pulsesrc_caps)?;
pulsesrc.link_filtered(&audiorate, &caps)?;
audiorate.link_pads(None, &audiomixer, Some("sink_%u"))?;
}

Expand Down

0 comments on commit 79f83d9

Please sign in to comment.