Changeset 370:925790633b2a in roaraudio


Ignore:
Timestamp:
08/03/08 14:49:05 (16 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added some BASIC PLAY like functions

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • include/libroardsp/midi.h

    r367 r370  
    2626#define ROAR_MIDI_TYPE_SINE 1 
    2727 
     28struct roar_midi_len { 
     29 int mul; 
     30 int div; 
     31}; 
     32 
    2833struct roar_note_octave { 
    2934 uint16_t       note; 
     
    3136 int            octave; 
    3237 float          freq; 
    33  int            len_mul; 
    34  int            len_div; 
     38 struct roar_midi_len len; 
    3539}; 
    3640 
     41 
     42struct roar_midi_basic_state { 
     43 struct roar_midi_len    len; 
     44 struct roar_note_octave note; 
     45}; 
    3746 
    3847char         * roar_midi_note2name   (uint16_t note); 
     
    4857int            roar_midi_gen_tone    (struct roar_note_octave * note, int16_t * samples, float t, int rate, int channels, int type, void * opts); 
    4958 
     59 
     60int roar_midi_play_note  (struct roar_stream * stream, struct roar_note_octave * note, float len); 
     61 
     62int roar_midi_basic_init (struct roar_midi_basic_state * state); 
     63int roar_midi_basic_play (struct roar_stream * stream, struct roar_midi_basic_state * state, char * notes); 
     64 
    5065#endif 
    5166 
  • libroardsp/midi.c

    r369 r370  
    117117} 
    118118 
     119 
     120int roar_midi_play_note  (struct roar_stream * stream, struct roar_note_octave * note, float len) { 
     121 return -1; 
     122} 
     123 
     124int roar_midi_basic_init (struct roar_midi_basic_state * state) { 
     125 if (!state) 
     126  return -1; 
     127 
     128 state->len.mul = 1; 
     129 state->len.div = 60; 
     130 
     131 state->note.note   = ROAR_MIDI_NOTE_NONE; 
     132 state->note.octave = 0; 
     133 
     134 return 0; 
     135} 
     136 
     137int roar_midi_basic_play (struct roar_stream * stream, struct roar_midi_basic_state * state, char * notes) { 
     138 struct roar_midi_basic_state is; 
     139 char   cn[ROAR_MIDI_MAX_NOTENAME_LEN+1] = {0}; 
     140 int i; 
     141 int have = 0; 
     142 struct roar_note_octave * n; 
     143 
     144 if ( !notes ) 
     145  return -1; 
     146 
     147 if ( state == NULL ) { 
     148  state = &is; 
     149  roar_midi_basic_init(state); 
     150 } 
     151 
     152 n = &(state->note); 
     153 
     154 for (; *notes != 0; notes++) { 
     155  if ( *notes == '>' ) { 
     156   n->octave++; 
     157  } else if ( *notes == '<' ) { 
     158   n->octave--; 
     159  } else if ( *notes != ' ' ) { 
     160   have++; 
     161  } 
     162 
     163  if (have) { 
     164   roar_midi_play_note(stream, n, 60 * state->len.mul / state->len.div); 
     165   have = 0; 
     166  } 
     167 } 
     168 
     169 return 0; 
     170} 
     171 
    119172//ll 
Note: See TracChangeset for help on using the changeset viewer.