示例#1
0
int mdx_parse_mml_ym2151_async(void* in_self)
{
    int i;
    long count;
    struct timeval st,et;
    int infinite_loops;
    mdxmml_ym2151_instances* self = (mdxmml_ym2151_instances *)in_self;

    pcm8_clear_buffer_flush_flag();
    gettimeofday(&st, NULL);
    gettimeofday(&et, NULL);

loop:
    if (self->all_track_finished==FLAG_TRUE) {
        return FLAG_FALSE;
    }

    if ( self->fade_out > 0 ) {
        if ( self->fade_out_wait==0 ) {
            self->fade_out_wait = self->fade_out;
        }
        self->fade_out_wait--;
        if ( self->fade_out_wait==0 ) {
            self->master_volume--;
        }
        if ( self->master_volume==0 ) {
            return FLAG_FALSE;
        }
    }
    ym2151_set_master_volume( self->master_volume * self->mdx->fm_volume / 127 );
    pcm8_set_master_volume( self->master_volume * self->mdx->pcm_volume / 127 );

    self->all_track_finished=FLAG_TRUE;
    infinite_loops = 32767; /* large enough */

    for ( i=0 ; i<self->mdx->tracks ; i++ ) {

        if ( self->mdx->track[i].waiting_sync == FLAG_TRUE )
        {
            continue;
        }

        count = self->mdx->track[i].counter;
        if ( count < 0 ) {
            continue;    /* this track has finished */
        }
        self->all_track_finished=FLAG_FALSE;

        self->mdx->track[i].gate--;
        if ( self->mdx->track[i].gate == 0 ) {
            note_off( i );
        }

        if ( i<8 ) {
            ym2151_set_freq_volume( i ); /* do portament, lfo, detune */
        }

        count--;
        while ( count == 0 ) {
            count=set_new_event( i );
        }

        self->mdx->track[i].counter = count;
        if ( infinite_loops > self->mdx->track[i].infinite_loop_times ) {
            infinite_loops = self->mdx->track[i].infinite_loop_times;
        }
    }

    if ( self->mdx->max_infinite_loops > 0 ) {
        if ( infinite_loops >= self->mdx->max_infinite_loops ) {
            self->fade_out = self->mdx->fade_out_speed;
        }
    }

    /* timer count */

    self->mdx->total_count++;
    self->mdx->elapsed_time += 1000*1024*(256 - self->mdx->tempo)/4000;

    /*  st.tv_usec += 1000* 1024*(256 - self->mdx->tempo)/4000;
      while ( st.tv_usec >= 1000*1000 ) {
        st.tv_usec-=1000*1000;
        st.tv_sec++;
      }

      while( timercmp(&st,&et,>) ) {
        do_pcm8();
        et.tv_usec += PCM8_SYSTEM_RATE*1000;
        while ( et.tv_usec >= 1000*1000 ) {
          et.tv_usec-=1000*1000;
          et.tv_sec++;
        }
      }

      if (pcm8_buffer_flush_flag()==FLAG_FALSE) {
        goto loop;
      }*/

    return FLAG_TRUE;
}
示例#2
0
int
mdx_parse_mml_ym2151_async(songdata *data)
{
  int i;
  long count;
  int infinite_loops;
  __GETSELF(data)

  pcm8_clear_buffer_flush_flag(data);
 loop:
  if (self->all_track_finished==FLAG_TRUE) {
    return FLAG_FALSE;
  }

  if ( self->fade_out > 0 ) {
    if ( self->fade_out_wait==0 ) { self->fade_out_wait = self->fade_out; }
    self->fade_out_wait--;
    if ( self->fade_out_wait==0 ) { self->master_volume--; }
    if ( self->master_volume==0 ) { return FLAG_FALSE; }
  }
  ym2151_set_master_volume( self->master_volume * self->mdx->fm_volume / 127, data );
  pcm8_set_master_volume( self->master_volume * self->mdx->pcm_volume / 127, data );

  self->all_track_finished=FLAG_TRUE;
  infinite_loops = 32767; /* large enough */

  for ( i=0 ; i<self->mdx->tracks ; i++ ) {

    if ( self->mdx->track[i].waiting_sync == FLAG_TRUE )
      { continue; }

    count = self->mdx->track[i].counter;
    if ( count < 0 ) { continue; } /* this track has finished */
    self->all_track_finished=FLAG_FALSE;
    
    self->mdx->track[i].gate--;
    if ( self->mdx->track[i].gate == 0 ) { note_off( i, data ); }
    
    if ( i<8 ) {
      ym2151_set_freq_volume( i, data ); /* do portament, lfo, detune */
    }

    count--;
    while ( count == 0 ) {
      count=set_new_event( i, data );
    }

    self->mdx->track[i].counter = count;
    if ( infinite_loops > self->mdx->track[i].infinite_loop_times ) {
      infinite_loops = self->mdx->track[i].infinite_loop_times;
    }
  }

  if ( self->mdx->max_infinite_loops > 0 ) {
    if ( infinite_loops >= self->mdx->max_infinite_loops ) {
      self->fade_out = self->mdx->fade_out_speed;
    }
  }

  /* timer count */

  self->mdx->total_count++;
  self->mdx->elapsed_time += 1000*1024*(256 - self->mdx->tempo)/4000;

  return FLAG_TRUE;
}