Changeset 2426:122c29dbcd87 in roaraudio


Ignore:
Timestamp:
08/19/09 05:12:09 (15 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added very basic code for synth

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • include/libroardsp/synth.h

    r2425 r2426  
    3838#include "libroardsp.h" 
    3939 
     40#define ROAR_SYNTH_FUNC_TYPE(name) float (*name)(float t, struct roar_synth_state * state) 
     41#define ROAR_SYNTH_FUNC_CAST(name) ((ROAR_SYNTH_FUNC_TYPE()) name) 
     42 
     43// SYNF -> Synthesis Function 
     44#define ROAR_SYNTH_SYNF_SINE ROAR_SYNTH_FUNC_CAST(sinf) 
     45 
     46struct roar_synth_state { 
     47 int rate; 
     48 struct roar_note_octave * note; 
     49 ROAR_SYNTH_FUNC_TYPE(func); 
     50 size_t pcmoffset; 
     51}; 
     52 
     53int roar_synth_init(struct roar_synth_state * state, struct roar_note_octave * note, int rate); 
     54int roar_synth_set_offset(struct roar_synth_state * state, size_t offset); 
     55int roar_synth_set_func  (struct roar_synth_state * state, ROAR_SYNTH_FUNC_TYPE(func)); 
     56 
     57int roar_synth_pcmout_i16n(struct roar_synth_state * state, int16_t * out, size_t frames, int channels); 
     58int roar_synth_pcmout_i161(struct roar_synth_state * state, int16_t * out, size_t frames); 
     59 
    4060#endif 
    4161 
  • libroardsp/synth.c

    r2425 r2426  
    2525#include "libroardsp.h" 
    2626 
     27#define _CHECK_BASIC() if ( state == NULL ) return -1 
     28 
     29int roar_synth_init(struct roar_synth_state * state, struct roar_note_octave * note, int rate) { 
     30 _CHECK_BASIC(); 
     31 
     32 if ( rate <= 0 ) 
     33  return -1; 
     34 
     35 memset(state, 0, sizeof(struct roar_synth_state)); 
     36 
     37 state->note = note; // NULL is valid here! 
     38 state->rate = rate; 
     39 
     40 state->func = ROAR_SYNTH_SYNF_SINE; 
     41 
     42 return 0; 
     43} 
     44 
     45int roar_synth_set_offset(struct roar_synth_state * state, size_t offset) { 
     46 _CHECK_BASIC(); 
     47 
     48 state->pcmoffset = offset; 
     49 
     50 return 0; 
     51} 
     52 
     53int roar_synth_set_func  (struct roar_synth_state * state, ROAR_SYNTH_FUNC_TYPE(func)) { 
     54 _CHECK_BASIC(); 
     55 
     56 state->func = func; 
     57 
     58 return 0; 
     59} 
     60 
     61int roar_synth_pcmout_i16n(struct roar_synth_state * state, int16_t * out, size_t frames, int channels) { 
     62 _CHECK_BASIC(); 
     63 
     64 if ( out == NULL ) 
     65  return -1; 
     66 
     67 if ( frames == 0 ) 
     68  return 0; 
     69 
     70 switch (channels) { 
     71  case 1: return roar_synth_pcmout_i161(state, out, frames); 
     72  default: 
     73    return -1; 
     74 } 
     75 
     76 return 0; 
     77} 
     78 
     79int roar_synth_pcmout_i161(struct roar_synth_state * state, int16_t * out, size_t frames) { 
     80 _CHECK_BASIC(); 
     81 
     82 return -1; 
     83} 
     84 
    2785 
    2886//ll 
Note: See TracChangeset for help on using the changeset viewer.