Hann Window Generator

Overview

Hann Window

The Hann window, also known as the Cosine Bell, is named after the Austrian meteorologist Julius von Hann. The Hann window is a taper formed with a cosine raised above zero. It is used as one of many windowing functions for smoothing values. The The Hann window taper belongs to both the cosine-sum and sine-power families. Unlike the Hamming window, the Hann window’s end points touch zero.

The formula for the Hann window is:

w(n) = 0.5*(1 - cos(2pin/(N-1)))

Aside from its common use as a window function, the Q DSP library also utilizes the hann window generator for modulating the audio signal and generating complex envelopes.

Include

#include <q/synth/hann_gen.hpp>

Declaration

struct hann_gen
{
            hann_gen(duration width, float sps);

   float    operator()();
   void     config(duration width, float sps;
   void     reset();
   void     midpoint();
};

Expressions

hann_gen is a model of Generator. In addition to valid expressions for Generator, hann_gen allows these expressions.

Notation

g

Object of type hann_gen.

w

Object of type duration.

sps

Floating point value representing samples per second.

Constructor

Expression Semantics

hann_gen(w, sps)

Construct hann_gen given window width, w, and samples per second, sps.

C++ brace initialization may also be used.

Mutators

Expression Semantics

g.config(w, sps)

Set the window width, w, with samples per second, sps.

g.reset()

Set the current phase to the start of the window.

g.midpoint()

Set the current phase to the middle of the window.

Ramp Generators

Two subclasses of hann_gen are specialized for ramp generation:

  1. The Hann upward ramp generator generates a rising curve with the shape of the first half of a Hann window taper.

  2. The Hann downward ramp generator generates a falling curve with the shape of the second half of a Hann window taper.

Declaration

struct hann_upward_ramp_gen : hann_gen
{
            hann_upward_ramp_gen(duration width, float sps);

   void     config(duration width, float sps);
};

struct hann_downward_ramp_gen : hann_gen
{
            hann_downward_ramp_gen(duration width, float sps);

   void     reset();
   void     config(duration width, float sps);
};

Expressions

hann_upward_ramp_gen and struct hann_downward_ramp_gen : hann_gen ` are a models of `Ramp and implements all valid expressions of Ramp.