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

Converts the output of ptttl_parse() into a WAV file. No dynamic memory allocation, and no loading the entire WAV file in memory. More...

#include "ptttl_parser.h"
#include "ptttl_sample_generator.h"

Go to the source code of this file.

Macros

#define PTTTL_WAVFILE_GENERATION_STRATEGY   0
 

Functions

int ptttl_to_wav (ptttl_parser_t *parser, FILE *fp, ptttl_sample_generator_config_t *config, ptttl_waveform_type_e wave_type)
 

Detailed Description

Converts the output of ptttl_parse() into a WAV file. No dynamic memory allocation, and no loading the entire WAV file in memory.

Requires ptttl_parser.c and ptttl_sample_generator.c

Requires stdint.h, and fopen/fseek/fwrite from stdio.h

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

Author
Erik Nyquist

Macro Definition Documentation

◆ PTTTL_WAVFILE_GENERATION_STRATEGY

#define PTTTL_WAVFILE_GENERATION_STRATEGY   0

Defines the strategy used by ptttl_to_wav to generate .wav files. The available options make various trade-offs between dynamic memory usage, performance, and composability:

  • 0 (default): Seeking not allowed, dynamic memory allocation not allowed. This is the most portable and composable strategy. No dynamic/heap memory will be used, and no seek operations will be performed on the output file stream (allowing 'stdout' connected to a shell pipe to be used as the output stream, for example). Due to the fact that we need to know how many sample points / frames there will be in order to generate the first few .wav bytes containing the header, and no seeking is allowed, this strategy comes with a performance cost, since the parser & sample generator must make two full passes of the input text; once to determine the total number of sample points / frames the generated .wav file will contain, and again to obtain the sample point / frame values for writing to the output stream.
  • 1: Seeking not allowed, dynamic memory allocation allowed. This option is more performant than 0, at the cost of dynamic memory allocation being required. Seek operations will not be performed on the output stream, but dynamic memory allocations will be performed.
  • 2: Seeking allowed, dynamic memory allocation not allowed. This strategy is the most performant, at the cost of composability. Seek operations will be performed on the output file stream, so only one pass of the parser & sample generator are required. No dynamic memory allocation will be performed.

Function Documentation

◆ ptttl_to_wav()

int ptttl_to_wav ( ptttl_parser_t parser,
FILE *  fp,
ptttl_sample_generator_config_t config,
ptttl_waveform_type_e  wave_type 
)

Convert PTTTL/RTTTL source to .wav file

Parameters
parserPointer to initialized parser object
fpFile stream that has already been opened for writing. Generated contents of .wav file will be written here.
configPointer to configuration for sample generator. May be NULL. If NULL, a default configuration will be used.
wave_typeWaveform type to use for all channels
Returns
0 if successful, -1 if an error occurred. Call ptttl_parser_error for an error description if -1 is returned.