Home --> Documentations --> PJMEDIA Reference

Waveform Similarity Based Overlap-Add (WSOLA)

Time-scale modification to audio without affecting the pitch. More...


typedef typedefPJ_BEGIN_DECL struct pjmedia_wsola pjmedia_wsola


enum  pjmedia_wsola_option {


pj_status_t pjmedia_wsola_create (pj_pool_t *pool, unsigned clock_rate, unsigned samples_per_frame, unsigned channel_count, unsigned options, pjmedia_wsola **p_wsola)
pj_status_t pjmedia_wsola_set_max_expand (pjmedia_wsola *wsola, unsigned msec)
pj_status_t pjmedia_wsola_destroy (pjmedia_wsola *wsola)
pj_status_t pjmedia_wsola_reset (pjmedia_wsola *wsola, unsigned options)
pj_status_t pjmedia_wsola_save (pjmedia_wsola *wsola, pj_int16_t frm[], pj_bool_t prev_lost)
pj_status_t pjmedia_wsola_generate (pjmedia_wsola *wsola, pj_int16_t frm[])
pj_status_t pjmedia_wsola_discard (pjmedia_wsola *wsola, pj_int16_t buf1[], unsigned buf1_cnt, pj_int16_t buf2[], unsigned buf2_cnt, unsigned *erase_cnt)

Detailed Description

This section describes Waveform Similarity Based Overlap-Add (WSOLA) implementation in PJMEDIA. The WSOLA API here can be used both to compress (speed-up) and stretch (expand, slow down) audio playback without altering the pitch, or as a mean for performing packet loss concealment (WSOLA).

The WSOLA implementation is used by Adaptive Delay Buffer and Packet Lost Concealment (PLC).

Typedef Documentation

◆ pjmedia_wsola

typedef typedefPJ_BEGIN_DECL struct pjmedia_wsola pjmedia_wsola

Opaque declaration for WSOLA structure.

Enumeration Type Documentation

◆ pjmedia_wsola_option

WSOLA options, can be combined with bitmask operation.


Disable Hanning window to conserve memory.


Specify that the WSOLA will not be used for PLC.


Specify that the WSOLA will not be used to discard frames in non-contiguous buffer.


Disable fade-in and fade-out feature in the transition between actual and synthetic frames in WSOLA. With fade feature enabled, WSOLA will only generate a limited number of synthetic frames (configurable with pjmedia_wsola_set_max_expand()), fading out the volume on every more samples it generates, and when it reaches the limit it will only generate silence.

Function Documentation

◆ pjmedia_wsola_create()

pj_status_t pjmedia_wsola_create ( pj_pool_t pool,
unsigned  clock_rate,
unsigned  samples_per_frame,
unsigned  channel_count,
unsigned  options,
pjmedia_wsola **  p_wsola 

Create and initialize WSOLA.

poolPool to allocate memory for WSOLA.
clock_rateSampling rate of audio playback.
samples_per_frameNumber of samples per frame.
channel_countNumber of channels.
optionsOption flags, bitmask combination of pjmedia_wsola_option.
p_wsolaPointer to receive WSOLA structure.
PJ_SUCCESS or the appropriate error code.

◆ pjmedia_wsola_set_max_expand()

pj_status_t pjmedia_wsola_set_max_expand ( pjmedia_wsola wsola,
unsigned  msec 

Specify maximum number of continuous synthetic frames that can be generated by WSOLA, in milliseconds. This option will only take effect if fading is not disabled via the option when the WSOLA session was created. Default value is PJMEDIA_WSOLA_MAX_EXPAND_MSEC (see also the documentation of PJMEDIA_WSOLA_MAX_EXPAND_MSEC for more information).

wsolaThe WSOLA session
msecThe duration.
PJ_SUCCESS normally.

◆ pjmedia_wsola_destroy()

pj_status_t pjmedia_wsola_destroy ( pjmedia_wsola wsola)

Destroy WSOLA.

wsolaWSOLA session.
PJ_SUCCESS normally.

◆ pjmedia_wsola_reset()

pj_status_t pjmedia_wsola_reset ( pjmedia_wsola wsola,
unsigned  options 

Reset the buffer contents of WSOLA.

wsolaWSOLA session.
optionsReset options, must be zero for now.
PJ_SUCCESS normally.

◆ pjmedia_wsola_save()

pj_status_t pjmedia_wsola_save ( pjmedia_wsola wsola,
pj_int16_t  frm[],
pj_bool_t  prev_lost 

Give one good frame to WSOLA to be kept as reference. Application must continuously give WSOLA good frames to keep its session up to date with current playback. Depending on the WSOLA implementation, this function may modify the content of the frame.

wsolaWSOLA session.
frmThe frame, which length must match the samples per frame setting of the WSOLA session.
prev_lostIf application previously generated a synthetic frame with pjmedia_wsola_generate() before calling this function, specify whether that was because of packet lost. If so, set this parameter to PJ_TRUE to make WSOLA interpolate this frame with its buffer. Otherwise if this value is PJ_FALSE, WSOLA will just append this frame to the end of its buffer.
PJ_SUCCESS normally.

◆ pjmedia_wsola_generate()

pj_status_t pjmedia_wsola_generate ( pjmedia_wsola wsola,
pj_int16_t  frm[] 

Generate one synthetic frame from WSOLA.

wsolaWSOLA session.
frmBuffer to receive the frame.
PJ_SUCCESS normally.

◆ pjmedia_wsola_discard()

pj_status_t pjmedia_wsola_discard ( pjmedia_wsola wsola,
pj_int16_t  buf1[],
unsigned  buf1_cnt,
pj_int16_t  buf2[],
unsigned  buf2_cnt,
unsigned *  erase_cnt 

Compress or compact the specified buffer by removing some audio samples from the buffer, without altering the pitch. For this function to work, total length of the buffer must be more than twice erase_cnt.

wsolaWSOLA session.
buf1Pointer to buffer.
buf1_cntNumber of samples in the buffer.
buf2Pointer to second buffer, if the buffer is not contiguous. Otherwise this parameter must be NULL.
buf2_cntNumber of samples in the second buffer, if the buffer is not contiguous. Otherwise this parameter should be zero.
erase_cntOn input, specify the number of samples to be erased. This function may erase more or less than the requested number, and the actual number of samples erased will be given on this argument upon returning from the function.
PJ_SUCCESS if some samples have been erased, PJ_ETOOSMALL if buffer is too small to be reduced, PJ_EINVAL if any of the parameters are not valid.


PJMEDIA small footprint Open Source media stack
Copyright (C) 2006-2008 Teluu Inc.