pub struct Spectrogram { /* private fields */ }Expand description
Spectra against time: each pushed spectrum (the
magnitudes of its bins, lowest frequency first) becomes a row, the
newest at the top, and older rows move down until capacity are kept.
- Each column stands for a span of frequencies: the bins are spread
across the width, evenly, or by their logarithm with
scale(AxisScale::Log)so each octave takes the same width. A column covering several bins shows the loudest; one between bins (the low end of a log scale) shows the nearest.resolutionsays how many Hz apart the bins are andboundswhich frequencies the width spans (default: every bin, from 0 Hz). - Levels are scaled from the smallest to the largest kept (or
range) into the shades of aHeatmap:░▒▓█in blocks,.:-=+*#%@in ASCII, and with colour thechart.heat.Nstyles, cold to hot. A NaN level is·(?in ASCII); an infinite one is drawn at the end it passes, so the decibels of silence (-inf) are the lowest shade. Feed it decibels (20 log10(magnitude)) to see quiet partials beside loud ones. - It fills the height it is given (a
Layoutregion, an intuiTUIve node) unlessheightis set; given none, it is as tall as the rows it holds. Rows below the oldest are blank.
use rich::Console;
use rich_ext::chart::{Charset, Spectrogram};
let console = Console::builder().width(4).color_system(None).build();
let mut waterfall = Spectrogram::new(3).charset(Charset::Ascii).range(0.0, 9.0);
waterfall.push([9.0, 0.0, 0.0, 0.0]);
waterfall.push([0.0, 9.0, 0.0, 0.0]);
waterfall.push([0.0, 0.0, 9.0, 4.5]);
// The newest at the top.
assert_eq!(console.render_export(&waterfall), " @+\n @ \n@ \n");
waterfall.push([0.0; 4]);
// Three kept: the oldest has gone.
assert_eq!(console.render_export(&waterfall), " \n @+\n @ \n");Implementations§
Source§impl Spectrogram
impl Spectrogram
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
An empty spectrogram keeping the newest capacity spectra (at
least one).
Sourcepub fn push(&mut self, bins: impl IntoIterator<Item = f64>)
pub fn push(&mut self, bins: impl IntoIterator<Item = f64>)
Add a spectrum at the top: the levels of its bins, lowest frequency
first. The oldest goes once there are capacity.
Sourcepub fn row(self, bins: impl IntoIterator<Item = f64>) -> Self
pub fn row(self, bins: impl IntoIterator<Item = f64>) -> Self
push as a builder.
Sourcepub fn range(self, min: f64, max: f64) -> Self
pub fn range(self, min: f64, max: f64) -> Self
The levels shaded lowest and highest (default: the smallest and largest kept). Levels outside are drawn at the end they pass.
Sourcepub fn resolution(self, hz: f64) -> Self
pub fn resolution(self, hz: f64) -> Self
How many Hz apart the bins are (default 1): rate / n for a
spectrum of n samples taken at rate. Bin i is at
i × resolution Hz.
Sourcepub fn bounds(self, low: f64, high: f64) -> Self
pub fn bounds(self, low: f64, high: f64) -> Self
The frequencies the width spans, in Hz (default: every bin, from 0
Hz to the top of the last; from the first bin above 0 on a log
scale). Bin i covers i × resolution up to the next bin.
Sourcepub fn scale(self, scale: AxisScale) -> Self
pub fn scale(self, scale: AxisScale) -> Self
How frequency runs across: evenly (the default) or by its logarithm.
Sourcepub fn charset(self, charset: Charset) -> Self
pub fn charset(self, charset: Charset) -> Self
Which glyphs to draw with (default Charset::Auto: blocks, or
ASCII on an ASCII-only console).
Sourcepub fn height(self, rows: usize) -> Self
pub fn height(self, rows: usize) -> Self
Height in rows (at most 65535), whatever height it is given.
Sourcepub fn level_scale(&self) -> Scale
pub fn level_scale(&self) -> Scale
The scale every level is shaded on.
Trait Implementations§
Source§impl AccessibleText for Spectrogram
Spectrogram, 12 spectra of 513 bins, 0 to 24k Hz, levels from 0 to 3,
then where the newest spectrum is loudest (Newest peaks at 440 Hz).
impl AccessibleText for Spectrogram
Spectrogram, 12 spectra of 513 bins, 0 to 24k Hz, levels from 0 to 3,
then where the newest spectrum is loudest (Newest peaks at 440 Hz).
Source§fn accessible_text(&self, _width: usize) -> String
fn accessible_text(&self, _width: usize) -> String
width where layout matters.Source§impl Clone for Spectrogram
impl Clone for Spectrogram
Source§impl Debug for Spectrogram
impl Debug for Spectrogram
Source§impl Draw for Spectrogram
impl Draw for Spectrogram
Source§impl PartialEq for Spectrogram
impl PartialEq for Spectrogram
Source§impl Renderable for Spectrogram
impl Renderable for Spectrogram
fn rich_render( &self, console: &Console, options: &ConsoleOptions, ) -> Vec<Segment>
Source§fn measure(&self, _console: &Console, options: &ConsoleOptions) -> Measurement
fn measure(&self, _console: &Console, options: &ConsoleOptions) -> Measurement
(minimum, maximum) cell width this renderable wants. Port of
__rich_measure__. The default is what upstream’s Measurement.get
returns for a renderable without one: anything from nothing to the
whole width, (0, max_width).Source§fn fit_to_measurement(&self) -> bool
fn fit_to_measurement(&self) -> bool
Console::print shrinks this renderable to its
measured width. Upstream renders every top-level renderable at the full
console width, so the default is false; an extension may opt in.Source§fn vertical(&self) -> Option<VerticalAlign>
fn vertical(&self) -> Option<VerticalAlign>
Table cell holding this renderable uses in
place of its column’s. Upstream reads getattr(renderable, "vertical", None); Align sets it.Source§fn print_end_line(&self, _options: &ConsoleOptions) -> bool
fn print_end_line(&self, _options: &ConsoleOptions) -> bool
"\n", so a print adds the final line break. A renderable
whose upstream output stops without one (Screen, LiveRender, a
Rule whose end has no newline) returns false, and the next
output continues its last line. options are the print’s options.