Blame src/waves.h

Packit c32a2d
#ifndef MPG123_WAVES_H
Packit c32a2d
#define MPG123_WAVES_H
Packit c32a2d
/*
Packit c32a2d
	waves: some oscillators, for fun
Packit c32a2d
Packit c32a2d
	copyright 2017 by the mpg123 project, license: LGPL 2.1
Packit c32a2d
Packit c32a2d
	This originates from Thomas' DerMixD, but the idea is probably generic
Packit c32a2d
	enough: Construct a buffer containing a lookup table that covers some
Packit c32a2d
	periods (for fractinal relations between sampling frequency and generated
Packit c32a2d
	wave frequency).
Packit c32a2d
Packit c32a2d
	For added fun, this not only has a single oscillator, but combines any
Packit c32a2d
	number of them (multiplicative).
Packit c32a2d
Packit c32a2d
	Storage format is interleaved PCM samples.
Packit c32a2d
*/
Packit c32a2d
Packit c32a2d
#include "config.h"
Packit c32a2d
#include "compat.h"
Packit c32a2d
#include "fmt123.h"
Packit c32a2d
Packit c32a2d
struct wave_table
Packit c32a2d
{
Packit c32a2d
	void *buf; /* period buffer */
Packit c32a2d
	struct mpg123_fmt fmt;
Packit c32a2d
	size_t samples; /* samples (PCM frames) in period buffer */
Packit c32a2d
	size_t offset;  /* offset in buffer for extraction helper */
Packit c32a2d
	size_t count;   /* number of combined waves */
Packit c32a2d
	double *freq;   /* actual wave frequency list */
Packit c32a2d
};
Packit c32a2d
Packit c32a2d
extern const char *wave_pattern_default;
Packit c32a2d
extern const char *wave_pattern_list;
Packit c32a2d
Packit c32a2d
/* Depending on your selection of frequencies, a very large table */
Packit c32a2d
/* might be required to cover them properly. You are required to provide */
Packit c32a2d
/* a limit for the table size, prompting adjustment on the frequencies */
Packit c32a2d
/* to make things fit. The limit is not strict, it can be overstepped by */
Packit c32a2d
/* about one period of one of the configured waveforms. */
Packit c32a2d
struct wave_table* wave_table_new(
Packit c32a2d
	long rate, int channels, int encoding /* desired output format */
Packit c32a2d
,	size_t count, double *freq /* required: number and frequencies of waves */
Packit c32a2d
,	const char** pattern       /* optional: wave pattern list */
Packit c32a2d
,	double *phase /* optional: phase shift list  */
Packit c32a2d
,	size_t size_limit /* non-strict upper limit for table size */
Packit c32a2d
);
Packit c32a2d
Packit c32a2d
/* The destructor. Returns NULL, always. */
Packit c32a2d
void* wave_table_del(struct wave_table* handle);
Packit c32a2d
Packit c32a2d
/* Extract the desired amount of samples (PCM frames). */
Packit c32a2d
/* Returns said amount of samples, too, if successful. */
Packit c32a2d
size_t wave_table_extract( struct wave_table *handle
Packit c32a2d
,	void *dest, size_t samples );
Packit c32a2d
Packit c32a2d
#endif