/* sound.h -- declarations for sound functions and structs. */ #define SAMPLE 1 #define SECOND 44100 #define MINUTE (60*SECOND) #define HOUR (60*MINUTE) #define CYCLE ( 2.0 * M_PI ) #define MIDI_MIDDLE_C 60 #define MIDI_A440 69 #ifndef TRUE #define TRUE 1 #define FALSE 0 #endif long count255; typedef struct SoundStream { FILE *byte_stream; int little_endian; } SoundStream; typedef struct PinkRng { int n_octaves; int counter; double rnds[ 1 ]; /* and ( n_octaves - 1 ) to follow. */ } PinkRng; typedef struct PyramidRng { char *rng_state; // rng for choices, not for offsets int n_levels; int n_notes; int i; int copy_a_lot; double range; int quantize; double *buffer; int *subchunks_used; double notes[ 1 ]; /* and ( n_notes - 1 ) to follow. */ } PyramidRng; typedef struct Delay { int len; int i; int filled; double samples[ 1 ]; /* and ( len - 1 ) to follow. */ } Delay; typedef struct All_pass { Delay *pDelay; double gain; } All_pass; SoundStream *sound_open_stream( FILE *byte_stream, char *mode, char *format ); void sound_close( SoundStream *pSS ); typedef struct NoteParam { // These go in an array. char *label; // NULL label marks the end of the array. union{ double value; char *string; } u; } NoteParam; NoteParam *noteParam_find( NoteParam *params, char *label ); double noteParam_get( NoteParam *params, char *label, double dflt ); void noteParam_set( NoteParam *params, char *label, double value ); char *noteParam_get_string( NoteParam *params, char *label, char *dflt ); void noteParam_set_string( NoteParam *params, char *label, char *string ); typedef struct NoteStream { void (*playNote) ( struct NoteStream *pNS, NoteParam *pNote ); void (*close) ( struct NoteStream *pNS ); void *data; } NoteStream; NoteStream *noteStream_open_SoundStream( SoundStream *pSS ); NoteStream *noteStream_open_MidiFile( FILE *byte_stream ); void noteStream_rest( NoteStream *pNS, double length ); void noteStream_put_meta_text( NoteStream *pNS, char *text ); void noteStream_put_copyright( NoteStream *pNS, char *text ); void noteStream_put_track_name( NoteStream *pNS, char *text ); short encode_sample( double sample ); void sound_write_short( unsigned short y, SoundStream *pSS ); void write_sample( double sample, SoundStream *pSS ); void write_LR_short( short left, short right, SoundStream *pSS ); void write_LR( double left, double right, SoundStream *pSS ); #define decode_sample(y) (((y) + .5 ) / 32768.0) /* These return 2 for success, 0 for error or eof. */ int sound_read_short( SoundStream *pSS, short *p_n ); int read_sample( SoundStream *pSS, double *p_sample ); /* These return 4 for success, 0 for error or eof. */ int read_LR( SoundStream *pSS, double *p_left, double *p_right ); int read_LR_short( SoundStream *pSS, short *p_left, short *p_right ); int sound_read_32bit( SoundStream *pSS, long *p_n ); int read_LR( SoundStream *pSS, double *p_left, double *p_right ); void boink( double freq, double length, double volume, double pan, SoundStream *pSS ); double rnd(); int random_lt( int n ); double chrom_freq( double chrom ); double midi_note_freq( double midi_note ); // Allows fractional midi notes. double randless_rnd( void ); PinkRng *pink_open( int n_octaves ); void pink_close( PinkRng *pPR ); double pink_rnd( PinkRng *pPR ); PyramidRng *pyramid_open( int n_octaves, char *rng_state, int copy_a_lot, double range, int quantize ); void pyramid_close( PyramidRng *pPR ); double pyramid_rnd( PyramidRng *pPR ); void fprint_time( FILE *stream, long t ); /* positive times only */ void fprint_time_step( FILE *stream, long t ); /* positive times only */ // Format is [+-][mmm:][SS][.[hh][{+-}sss]] long parse_time( char *str, int *p_is_relative, char **endptr ); Delay *delay_open( int len ); double delay( Delay *pDelay, double sample ); double delay_output( Delay *pDelay ); void delay_close( Delay *pDelay ); All_pass *all_pass_open( int len, double gain ); double all_pass( All_pass *pAll_pass, double sample ); void all_pass_close( All_pass *pAll_pass ); // turn a number between 0 and 1 into between min and max. double exp_portion( double x, double min, double max ); // turn a number between 0 and 1 into between min and max. double lin_portion( double x, double min, double max ); // turn a number between 0 and 1 into between min and max...really. double lin_portion_limit( double x, double min, double max );