ptttl v0.2.0
C implementation of a PTTTL parser. PTTTL is a superset of NOKIA's RTTTL that adds polyphony & vibrato.
Loading...
Searching...
No Matches
ptttl_sample_generator.h
Go to the documentation of this file.
1
16#ifndef PTTTL_SAMPLE_GENERATOR_H
17#define PTTTL_SAMPLE_GENERATOR_H
18
19
20#include <stdint.h>
21#include "ptttl_parser.h"
22
23
24#ifdef __cplusplus
25 extern "C" {
26#endif
27
28
32#define PTTTL_SAMPLE_GENERATOR_CONFIG_DEFAULT {.sample_rate=44100u, .attack_samples=100u, \
33 .decay_samples=500u, .amplitude=0.8f}
34
35
39typedef enum
40{
45 WAVEFORM_TYPE_COUNT
47
48
58typedef float (*ptttl_waveform_generator_t)(float x, float p, unsigned int s);
59
60
64typedef struct
65{
69 unsigned int sine_index;
70 unsigned int start_sample;
71 unsigned int num_samples;
72 unsigned int attack;
73 unsigned int decay;
74 unsigned int note_number;
75 float pitch_hz;
78
82typedef struct
83{
84 unsigned int sample_rate;
85 unsigned int attack_samples;
86 unsigned int decay_samples;
87 float amplitude;
89
93typedef struct
94{
95 unsigned int current_sample;
97 uint8_t channel_finished[PTTTL_MAX_CHANNELS_PER_FILE];
99 ptttl_parser_t *parser;
101
102
115
130 uint32_t channel, ptttl_waveform_type_e type);
131
146 uint32_t channel, ptttl_waveform_generator_t wgen);
147
163 uint32_t *num_samples, int16_t *samples);
164
165
166#ifdef __cplusplus
167 }
168#endif
169
170#endif // PTTTL_SAMPLE_GENERATOR_H
Parser for RTTTL (Ring Tone Text Transfer Language) and PTTTL (Polyphonic Tone Text Transfer Language...
#define PTTTL_MAX_CHANNELS_PER_FILE
Definition: ptttl_parser.h:46
float(* ptttl_waveform_generator_t)(float x, float p, unsigned int s)
Definition: ptttl_sample_generator.h:58
ptttl_waveform_type_e
Definition: ptttl_sample_generator.h:40
@ WAVEFORM_TYPE_TRIANGLE
Generates a triangle wave.
Definition: ptttl_sample_generator.h:42
@ WAVEFORM_TYPE_SINE
Generates a sine wave.
Definition: ptttl_sample_generator.h:41
@ WAVEFORM_TYPE_SQUARE
Generates a square wave.
Definition: ptttl_sample_generator.h:44
@ WAVEFORM_TYPE_SAWTOOTH
Generates a sawtooth wave.
Definition: ptttl_sample_generator.h:43
int ptttl_sample_generator_generate(ptttl_sample_generator_t *generator, uint32_t *num_samples, int16_t *samples)
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_custom_waveform(ptttl_sample_generator_t *generator, uint32_t channel, ptttl_waveform_generator_t wgen)
int ptttl_sample_generator_set_waveform(ptttl_sample_generator_t *generator, uint32_t channel, ptttl_waveform_type_e type)
Definition: ptttl_sample_generator.h:65
unsigned int start_sample
The sample index on which this note started.
Definition: ptttl_sample_generator.h:70
float phasor_state
Phasor state for vibrato (frequency modulation)
Definition: ptttl_sample_generator.h:76
uint32_t vibrato_variance
Vibrato variance, in HZ.
Definition: ptttl_sample_generator.h:68
uint32_t vibrato_frequency
Vibrato frequency, in HZ.
Definition: ptttl_sample_generator.h:67
unsigned int sine_index
Monotonically increasing index for sinf() function, note pitch.
Definition: ptttl_sample_generator.h:69
unsigned int num_samples
Number of samples this note runs for.
Definition: ptttl_sample_generator.h:71
ptttl_waveform_generator_t wgen
Waveform generator function.
Definition: ptttl_sample_generator.h:66
unsigned int note_number
Piano key number for this note, 1-88.
Definition: ptttl_sample_generator.h:74
float pitch_hz
Note pitch in Hz.
Definition: ptttl_sample_generator.h:75
unsigned int attack
Note decay length, in samples.
Definition: ptttl_sample_generator.h:72
unsigned int decay
Note decay length, in samples.
Definition: ptttl_sample_generator.h:73
Definition: ptttl_parser.h:159
Definition: ptttl_sample_generator.h:83
float amplitude
Amplitude of generated samples between 0.0-1.0, with 1.0 being full volume.
Definition: ptttl_sample_generator.h:87
unsigned int sample_rate
Sampling rate in samples per second (Hz)
Definition: ptttl_sample_generator.h:84
unsigned int attack_samples
no. of samples to ramp from 0 to full volume, at note start
Definition: ptttl_sample_generator.h:85
unsigned int decay_samples
no. of samples to ramp from full volume to 0, at note end
Definition: ptttl_sample_generator.h:86
Definition: ptttl_sample_generator.h:94