Changeset 2427:fd28722d924e in roaraudio


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

very simple mono synth

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroardsp/synth.c

    r2426 r2427  
    2626 
    2727#define _CHECK_BASIC() if ( state == NULL ) return -1 
     28#define _CHECK_PCMOUT() _CHECK_BASIC(); if ( frames == 0 ) return 0; if ( out == NULL ) return -1 
    2829 
    2930int roar_synth_init(struct roar_synth_state * state, struct roar_note_octave * note, int rate) { 
     
    5455 _CHECK_BASIC(); 
    5556 
     57 if ( func == NULL ) 
     58  return -1; 
     59 
    5660 state->func = func; 
    5761 
     
    6064 
    6165int 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; 
     66 _CHECK_PCMOUT(); 
    6967 
    7068 switch (channels) { 
     
    7876 
    7977int roar_synth_pcmout_i161(struct roar_synth_state * state, int16_t * out, size_t frames) { 
    80  _CHECK_BASIC(); 
     78 float t_step; 
     79 float t_cur; 
     80 int i; 
     81 
     82 _CHECK_PCMOUT(); 
     83 
     84 t_step = 1.0/state->rate; 
     85 
     86 t_cur  = t_step * state->pcmoffset; 
     87 
     88 for (i = 0; i < frames; i++, t_cur += t_step) { 
     89  out[i] = 32767.0*state->func(t_cur, state); 
     90 } 
     91 
     92 state->pcmoffset += frames; 
    8193 
    8294 return -1; 
Note: See TracChangeset for help on using the changeset viewer.