|
ptttl v0.2.0
C implementation of a PTTTL parser. PTTTL is a superset of NOKIA's RTTTL that adds polyphony & vibrato.
|
Converts the output of ptttl_parse_next() into a stream of signed 16-bit audio samples suitable for a WAV file. Samples can be obtained one at a time, at your leisure. More...
Go to the source code of this file.
Classes | |
| struct | ptttl_note_stream_t |
| struct | ptttl_sample_generator_config_t |
| struct | ptttl_sample_generator_t |
Macros | |
| #define | PTTTL_SAMPLE_GENERATOR_CONFIG_DEFAULT |
Typedefs | |
| typedef float(* | ptttl_waveform_generator_t) (float x, float p, unsigned int s) |
Enumerations | |
| enum | ptttl_waveform_type_e { WAVEFORM_TYPE_SINE = 0 , WAVEFORM_TYPE_TRIANGLE , WAVEFORM_TYPE_SAWTOOTH , WAVEFORM_TYPE_SQUARE , WAVEFORM_TYPE_COUNT } |
Functions | |
| int | ptttl_sample_generator_create (ptttl_parser_t *parser, ptttl_sample_generator_t *generator, ptttl_sample_generator_config_t *config) |
| int | ptttl_sample_generator_set_waveform (ptttl_sample_generator_t *generator, uint32_t channel, ptttl_waveform_type_e type) |
| int | ptttl_sample_generator_set_custom_waveform (ptttl_sample_generator_t *generator, uint32_t channel, ptttl_waveform_generator_t wgen) |
| int | ptttl_sample_generator_generate (ptttl_sample_generator_t *generator, uint32_t *num_samples, int16_t *samples) |
Converts the output of ptttl_parse_next() into a stream of signed 16-bit audio samples suitable for a WAV file. Samples can be obtained one at a time, at your leisure.
Requires ptttl_parser.c
Requires stdint.h and memset() from string.h
See https://github.com/eriknyquist/ptttl for more details about PTTTL.
| #define PTTTL_SAMPLE_GENERATOR_CONFIG_DEFAULT |
ptttl_sample_generator_config_t object initialization with sane defaults
| typedef float(* ptttl_waveform_generator_t) (float x, float p, unsigned int s) |
Callback function for a waveform generator
| x | Phase; current position on the waveform, in turns (0.0 through 1.0) |
| p | Wave frequency in Hz |
| s | Sampling rate in Hz |
| int ptttl_sample_generator_create | ( | ptttl_parser_t * | parser, |
| ptttl_sample_generator_t * | generator, | ||
| ptttl_sample_generator_config_t * | config | ||
| ) |
Initialize a sample generator instance for a specific PTTTL/RTTTL source text
| parser | Pointer to initialized PTTTL parser object |
| generator | Pointer to generator instance to initialize |
| config | Pointer to sample generator configuration data |
| int ptttl_sample_generator_generate | ( | ptttl_sample_generator_t * | generator, |
| uint32_t * | num_samples, | ||
| int16_t * | samples | ||
| ) |
Generate the next audio sample(s) for an initialized generator object
| generator | Pointer to initialized generator object |
| num_samples | Pointer to number of samples to generate. If successful, then this pointer is re-used to write out the actual number of samples generated. |
| samples | Pointer to location to store sample values. The caller is expected to provide at least (sizeof(int16_t) * num_samples) bytes of storage for the generated samples. |
| int ptttl_sample_generator_set_custom_waveform | ( | ptttl_sample_generator_t * | generator, |
| uint32_t | channel, | ||
| ptttl_waveform_generator_t | wgen | ||
| ) |
Set a custom waveform generator function for a specific channel of the sample generator
| generator | Pointer to initialized generator object |
| channel | Channel index to set the waveform type for. Channel index is 0-based, and channels are indexed in the order in which they appear in the PTTTL source text. For example, channel 0 is the first channel that appears in the source text, channel 1 is the second channel, and so on. |
| wgen | Waveform generator function to use for the specified channel. |
| int ptttl_sample_generator_set_waveform | ( | ptttl_sample_generator_t * | generator, |
| uint32_t | channel, | ||
| ptttl_waveform_type_e | type | ||
| ) |
Set the built-in waveform type for a specific channel of the sample generator
| generator | Pointer to initialized generator object |
| channel | Channel index to set the waveform type for. Channel index is 0-based, and channels are indexed in the order in which they appear in the PTTTL source text. For example, channel 0 is the first channel that appears in the source text, channel 1 is the second channel, and so on. |
| type | Built-in waveform type to generate for the specified channel. |