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
Classes | Macros | Functions
ptttl_parser.h File Reference

Parser for RTTTL (Ring Tone Text Transfer Language) and PTTTL (Polyphonic Tone Text Transfer Language, superset of RTTTL which supports polyphony) More...

#include <stdint.h>

Go to the source code of this file.

Classes

struct  ptttl_output_note_t
 
struct  ptttl_parser_input_stream_t
 
struct  ptttl_parser_input_iface_t
 
struct  ptttl_parser_error_t
 
struct  ptttl_parser_t
 

Macros

#define PTTTL_VERSION   "v0.2.0"
 
#define PTTTL_MAX_CHANNELS_PER_FILE   (16u)
 
#define PTTTL_MAX_NAME_LEN   (256u)
 
#define PTTTL_NOTE_VIBRATO_FREQ(note)   (((note)->vibrato_settings) & 0xffffu)
 
#define PTTTL_NOTE_VIBRATO_VAR(note)   ((((note)->vibrato_settings) >> 16u) & 0xffffu)
 
#define PTTTL_NOTE_VALUE(note)   (((note)->note_settings) & 0x7fu)
 
#define PTTTL_NOTE_DURATION(note)   ((((note)->note_settings) >> 7u) & 0xffffu)
 

Functions

ptttl_parser_error_t ptttl_parser_error (ptttl_parser_t *state)
 
int ptttl_parse_init (ptttl_parser_t *parser, ptttl_parser_input_iface_t iface)
 
int ptttl_parse_next (ptttl_parser_t *parser, uint32_t channel_idx, ptttl_output_note_t *note)
 

Detailed Description

Parser for RTTTL (Ring Tone Text Transfer Language) and PTTTL (Polyphonic Tone Text Transfer Language, superset of RTTTL which supports polyphony)

Converts a PTTTL or RTTTL source file into a stream of ptttl_output_note_t objects, which is an intermediate representation that can be processed by ptttl_sample_generator.c to obtain PCM audio samples.

Requires stdint.h, strtoul() from stdlib.h, and memset() from string.h.

See https://github.com/eriknyquist/ptttl for more details about PTTTL.

Author
Erik K. Nyquist

Macro Definition Documentation

◆ PTTTL_MAX_CHANNELS_PER_FILE

#define PTTTL_MAX_CHANNELS_PER_FILE   (16u)

Maximum number of channels (note lanes) allowed in a single PTTTL file. This setting will significantly affect the size of the ptttl_parser_t and ptttl_sample_generator_t structs– more channels makes them larger.

◆ PTTTL_MAX_NAME_LEN

#define PTTTL_MAX_NAME_LEN   (256u)

Maximum size of the name (first colon-separated field in a PTTTL or RTTTL file). This name is stored directly in the ptttl_parser_t struct, so changing this size directly affects the size of the ptttl_parser_t struct.

Function Documentation

◆ ptttl_parse_init()

int ptttl_parse_init ( ptttl_parser_t parser,
ptttl_parser_input_iface_t  iface 
)

Initializes the PTTTL parser for a particular PTTTL/RTTTL input text. Must be called once before attempting to parse a PTTTL/RTTTL input text with ptttl_parse_next.

Parameters
parserPointer to parser object to initialize
ifaceInput interface for reading PTTTL/RTTTL source text
Returns
0 if successful, -1 otherwise. If -1, use ptttl_parser_error to get detailed error information.

◆ ptttl_parse_next()

int ptttl_parse_next ( ptttl_parser_t parser,
uint32_t  channel_idx,
ptttl_output_note_t note 
)

Read PTTTL/RTTTL source text for the next note of the specified channel, and produce an intermediate representation of the note that can be used to generate audio data.

Parameters
parserPointer to initialized parser object
channel_idxChannel number to get next note for. Channel numbers are in the same order that the channel occurs in the PTTTL/RTTTL source text, starting from 0.
notePointer to location to store intermediate representation of PTTTL/RTTTL note
Returns
0 if successful, 1 if there are no more notes available for the given channel, and -1 if parsing error occurred. If -1, use ptttl_parser_error to get detailed error information.

◆ ptttl_parser_error()

ptttl_parser_error_t ptttl_parser_error ( ptttl_parser_t state)

Return error info after ptttl_parse_init or ptttl_parse_next has returned -1

Returns
Object describing the error that occurred. error_message field will be NULL if no error has occurred.