/* * System Interface Library for games * Copyright (c) 2007-2020 Andrew Church * Released under the GNU GPL version 3 or later; NO WARRANTY is provided. * See the file COPYING.txt for details. * * src/test/sound/wavegen.h: Header for wave generators. */ #ifndef SIL_SRC_TEST_SOUND_WAVEGEN_H #define SIL_SRC_TEST_SOUND_WAVEGEN_H /*************************************************************************/ /*************************************************************************/ /* State buffer for square_gen() */ typedef struct SquareState SquareState; struct SquareState { int period; // Length of one cycle, in samples. int num_cycles; // Number of cycles to generate. int samples_out; // Number of samples generated so far. }; /*-----------------------------------------------------------------------*/ /** * square_gen: Generate a square wave at a given period and length. * The square wave has output +10000 for the first half of its cycle, * output -10000 for the second half. (If the period is an odd number, * the midpoint sample will have value -10000.) * * [Parameters] * handle: Audio data handle (SquareState pointer). * pcm_buffer: Output buffer for PCM samples. * pcm_len: Number of samples to retrieve. * [Return value] * True on success, false on end of stream or error. */ extern int square_gen(void *handle, void *pcm_buffer, int pcm_len); /** * stereo_square_gen: Generate a stereo pair of square waves, with the * left channel at a given period and the right channel at twice that * period (half the frequency). * * [Parameters] * handle: Audio data handle (SquareState pointer). * pcm_buffer: Output buffer for PCM samples. * pcm_len: Number of samples to retrieve. * [Return value] * True on success, false on end of stream or error. */ extern int stereo_square_gen(void *handle, void *pcm_buffer, int pcm_len); /** * sawtooth_gen: Generate a sawtooth wave that cycles through all 16-bit * sample values: 0,1,...,32767,-32768,...,1,0,1,... * * [Parameters] * handle: Audio data handle (pointer to int16_t: next sample value). * pcm_buffer: Output buffer for PCM samples. * pcm_len: Number of samples to retrieve. * [Return value] * True on success, false on end of stream or error. */ extern int sawtooth_gen(void *handle, void *pcm_buffer, int pcm_len); /** * sawtooth_gen: Generate a stereo sawtooth wave whose PCM data is * identical to that generated by sawtooth_gen(). Consequently, the left * channel will have even values (0,2,4,..). and the right channel will * have odd values (1,3,5,...). * * [Parameters] * handle: Audio data handle (pointer to int16_t: next sample value). * pcm_buffer: Output buffer for PCM samples. * pcm_len: Number of samples to retrieve. * [Return value] * True on success, false on end of stream or error. */ extern int sawtooth_stereo_gen(void *handle, void *pcm_buffer, int pcm_len); /*************************************************************************/ /*************************************************************************/ #endif // SIL_SRC_TEST_SOUND_WAVEGEN_H