Skip to contents

Resample numeric data to a different rate.

Usage

resample(x, source.rate, target.rate, ...)

Arguments

x

A numeric vector that needs to be resampled.

source.rate

The rate at which x was sampled in Hz (or another unit, as long as it is in the same unit as target.rate).

target.rate

The desired target sampling rate in Hz (or another unit, as long as it is in the same unit as source.rate).

...

Arguments passed on to stats::approx. To simulate the Commodore Amiga hardware, it's best to use 'method = "constant" for resampling 8 bit samples.

Value

Returns a resampled numeric

vector of length round(length(x) * target.rate / source.rate) based on x.

Details

This function resamples numeric data (i.e., audio data) from a source sample rate to a target sample rate. At the core it uses the stats::approx function.

Author

Pepijn de Vries

Examples

some.data <- 1:100

## assume that the current (sample) rate
## of 'some.data' is 100, and we want to
## resample this data to a rate of 200:
resamp.data <- resample(some.data, 100, 200, method = "constant")