Changeset 2432:d84ffcebf730 in roaraudio


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

added support to set volume

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • include/libroardsp/synth.h

    r2431 r2432  
    5454 ROAR_SYNTH_FUNC_TYPE(func); 
    5555 size_t pcmoffset; 
     56 float volume; 
    5657}; 
    5758 
     
    5960int roar_synth_set_offset(struct roar_synth_state * state, size_t offset); 
    6061int roar_synth_set_func  (struct roar_synth_state * state, ROAR_SYNTH_FUNC_TYPE(func)); 
     62int roar_synth_set_volume(struct roar_synth_state * state, float volume); 
    6163 
    6264int roar_synth_pcmout_i16n(struct roar_synth_state * state, int16_t * out, size_t frames, int channels); 
  • libroardsp/synth.c

    r2431 r2432  
    3636 memset(state, 0, sizeof(struct roar_synth_state)); 
    3737 
    38  state->note = note; // NULL is valid here! 
    39  state->rate = rate; 
     38 state->note   = note; // NULL is valid here! 
     39 state->rate   = rate; 
     40 state->volume = 1; 
    4041 
    4142 state->func = ROAR_SYNTH_SYNF_SINE; 
     
    5960 
    6061 state->func = func; 
     62 
     63 return 0; 
     64} 
     65 
     66int roar_synth_set_volume(struct roar_synth_state * state, float volume) { 
     67 _CHECK_BASIC(); 
     68 
     69 state->volume = volume; 
    6170 
    6271 return 0; 
     
    9099 
    91100 for (i = 0; i < frames; i++, t_cur += t_step) { 
    92   out[i] = 32767.0*state->func(2.0*M_PI*freq*t_cur, state); 
     101  out[i] = 32767.0*state->volume*state->func(2.0*M_PI*freq*t_cur, state); 
    93102 } 
    94103 
Note: See TracChangeset for help on using the changeset viewer.