miniDSP
A small C library for audio DSP
Loading...
Searching...
No Matches
minidsp_spectext.c File Reference

Spectrogram text art: synthesise audio that displays readable text when viewed as a spectrogram. More...

#include "minidsp.h"
#include "minidsp_internal.h"

Go to the source code of this file.

Functions

static int pixel_at (const char *text, unsigned len, unsigned col, unsigned row)
 Return the pixel state (0 or 1) at bitmap coordinate (col, row) for the given string.
unsigned MD_spectrogram_text (double *output, unsigned max_len, const char *text, double freq_lo, double freq_hi, double duration_sec, double sample_rate)
 Synthesise audio that displays readable text in a spectrogram.

Variables

static const unsigned char font_5x7 [95][5]

Detailed Description

Spectrogram text art: synthesise audio that displays readable text when viewed as a spectrogram.

A 5x7 bitmap font rasterises each printable ASCII character. Each bitmap column becomes a time slice; each "on" pixel becomes a sine wave at the corresponding frequency. A raised-cosine crossfade suppresses clicks at column boundaries.

Definition in file minidsp_spectext.c.

Function Documentation

◆ MD_spectrogram_text()

unsigned MD_spectrogram_text ( double * output,
unsigned max_len,
const char * text,
double freq_lo,
double freq_hi,
double duration_sec,
double sample_rate )

Synthesise audio that displays readable text in a spectrogram.

Given a short string, the function rasterises it with a built-in 5x7 bitmap font. Each bitmap column becomes a time slice; each "on" pixel becomes a sine wave at the corresponding frequency between freq_lo and freq_hi. A 3 ms raised-cosine crossfade suppresses clicks at column boundaries. The output is normalised to 0.9 peak amplitude.

Parameters
outputOutput buffer (caller-allocated).
max_lenSize of output in samples (must be >= returned value).
textPrintable ASCII string to render (must be non-empty).
freq_loLowest frequency in Hz (bottom of text).
freq_hiHighest frequency in Hz (top of text, must be < Nyquist).
duration_secTotal duration in seconds.
sample_rateSample rate in Hz.
Returns
Number of samples written to output.
double buf[64000];
unsigned n = MD_spectrogram_text(buf, 64000, "HELLO",
200.0, 7500.0, 2.0, 16000.0);
// buf[0..n-1] now contains synthesised audio; view its spectrogram
// to see "HELLO" spelled out in the frequency domain.
unsigned MD_spectrogram_text(double *output, unsigned max_len, const char *text, double freq_lo, double freq_hi, double duration_sec, double sample_rate)
Synthesise audio that displays readable text in a spectrogram.

Definition at line 144 of file minidsp_spectext.c.

◆ pixel_at()

int pixel_at ( const char * text,
unsigned len,
unsigned col,
unsigned row )
static

Return the pixel state (0 or 1) at bitmap coordinate (col, row) for the given string.

Characters are 5 columns wide with 3-column spacing. Rows are numbered 0 (top) to 6 (bottom).

Definition at line 123 of file minidsp_spectext.c.

Variable Documentation

◆ font_5x7

const unsigned char font_5x7[95][5]
static

Definition at line 22 of file minidsp_spectext.c.