Changeset 2469:e9f81bfa4020 in roaraudio


Ignore:
Timestamp:
08/22/09 02:34:25 (15 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

alloc buffers, and free them again

Location:
roard
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • roard/include/ssynth.h

    r2467 r2469  
    5353  int stage; 
    5454  char vv_down, vv_up; 
    55   struct roar_note_octave note; 
    56   struct roar_synth_state synth; 
    57   struct roar_fader_state fader; 
    58   struct roar_buffer      buf; 
     55  struct roar_note_octave   note; 
     56  struct roar_synth_state   synth; 
     57  struct roar_fader_state   fader; 
     58  struct roar_buffer      * buf; 
    5959 } notes[SSYNTH_NOTES_MAX]; 
    6060} g_ssynth; 
  • roard/ssynth.c

    r2468 r2469  
    8484 
    8585int ssynth_free (void) { 
     86 int i; 
     87 
    8688 if ( !ssynth_conf.enable ) 
    8789  return 0; 
    8890 
     91 for (i = 0; i < SSYNTH_NOTES_MAX; i++) { 
     92  if ( g_ssynth.notes[i].buf != NULL ) { 
     93   roar_buffer_free(g_ssynth.notes[i].buf); 
     94   g_ssynth.notes[i].buf = NULL; 
     95  } 
     96 } 
     97 
    8998 return streams_delete(g_ssynth.stream); 
    9099} 
    91100 
    92101int ssynth_update (void) { 
     102 struct roar_stream_server * ss; 
     103 struct roar_stream        *  s; 
     104 struct roar_buffer        * buf; 
     105 size_t buflen; 
     106 size_t needlen; 
     107 int i; 
     108 
     109 if ( !ssynth_conf.enable ) 
     110  return 0; 
     111 
     112 if ( streams_get(g_ssynth.stream, &ss) == -1 ) { 
     113  return -1; 
     114 } 
     115 
     116 s = ROAR_STREAM(ss); 
     117 
     118 needlen = ROAR_OUTPUT_CALC_OUTBUFSIZE(&(s->info)); 
     119 
     120 for (i = 0; i < SSYNTH_NOTES_MAX; i++) { 
     121  if ( g_ssynth.notes[i].stage != SSYNTH_STAGE_UNUSED ) { 
     122   if ( g_ssynth.notes[i].buf == NULL ) { 
     123    if ( roar_buffer_new(&buf, needlen) == -1 ) 
     124     continue; 
     125 
     126    g_ssynth.notes[i].buf = buf; 
     127   } else { 
     128    buf = g_ssynth.notes[i].buf; 
     129 
     130    if ( roar_buffer_get_len(buf, &buflen) == -1 ) 
     131     continue; 
     132 
     133    if ( buflen < needlen ) { 
     134     if ( roar_buffer_set_len(buf, needlen) == -1 ) 
     135      continue; 
     136    } 
     137   } 
     138  } 
     139 } 
     140 
    93141 return -1; 
    94142} 
Note: See TracChangeset for help on using the changeset viewer.