示例#1
0
/* pvshell_fetch -- computes h(f, g, x, y) where f and g are
 *  sounds, x and y are doubles, and h implemented via a function
 *  pointer. This could certainly be generalized further, but
 *  maybe we should take this one step at a time.
 */
void pvshell_fetch(snd_susp_type a_susp, snd_list_type snd_list)
{
    pvshell_susp_type susp = (pvshell_susp_type) a_susp;
    long n, flags;
    sample_block_type out;
    sample_block_values_type out_ptr;

    falloc_sample_block(out, "pvshell_fetch");
    out_ptr = out->samples;
    snd_list->block = out;

    n = max_sample_block_len; // ideally, compute a whole block of samples

    flags = (susp->pvshell.h)(&(susp->pvshell), out_ptr, &n, susp->susp.current);

    /* test for termination */
    if (flags & PVSHELL_FLAG_TERMINATE) {
        snd_list_terminate(snd_list);
    } else {
        snd_list->block_len = n;
        susp->susp.current += n;
    }
    /* test for logical stop */
    if (flags & PVSHELL_FLAG_LOGICAL_STOP || susp->logically_stopped) {
        snd_list->logically_stopped = true;
        susp->logically_stopped = true;
    }
} /* pvshell_fetch */
示例#2
0
文件: nyx.c 项目: andreipaga/audacity
void nyx_susp_fetch(register nyx_susp_type susp, snd_list_type snd_list)
{
   sample_block_type         out;
   sample_block_values_type  out_ptr;
   long                      n;
   int                       err;

   falloc_sample_block(out, "nyx_susp_fetch");
   out_ptr = out->samples;
   snd_list->block = out;

   n = max_sample_block_len;
   if (susp->susp.current + n > susp->len)
      n = susp->len - susp->susp.current;

   err = susp->callback(out_ptr, susp->channel,
                            susp->susp.current, n, susp->userdata);
   if (err)
      longjmp(nyx_cntxt.c_jmpbuf, 1);      

   snd_list->block_len = n;
   susp->susp.current += n;

   if (n == 0) {
      /* we didn't read anything, but can't return length zero, so
         convert snd_list to pointer to zero block */
      snd_list_terminate(snd_list);
   }
   else if (n < max_sample_block_len) {
      /* should free susp */
      snd_list_unref(snd_list->u.next);
      /* if something is in buffer, terminate by pointing to zero block */
      snd_list->u.next = zero_snd_list;
   }
}
示例#3
0
文件: pwl.c 项目: nausic/VimProject
void pwl__fetch(register pwl_susp_type susp, snd_list_type snd_list)
{
    int cnt = 0; /* how many samples computed */
    int togo;
    int n;
    sample_block_type out;
    register sample_block_values_type out_ptr;

    register sample_block_values_type out_ptr_reg;

    register double incr_reg;
    register double lvl_reg;
    falloc_sample_block(out, "pwl__fetch");
    out_ptr = out->samples;
    snd_list->block = out;

    while (cnt < max_sample_block_len) { /* outer loop */
        /* first compute how many samples to generate in inner loop: */
        /* don't overflow the output sample block: */
        togo = max_sample_block_len - cnt;


        if (susp->bpt_ptr == NULL) {
out:
            togo = 0;	/* indicate termination */
            break;	/* we're done */
        }
        {   long cur = susp->susp.current + cnt;
            long nn = getfixnum(car(susp->bpt_ptr)) - cur;
            if (nn == 0) {
                if (compute_lvl(susp) || compute_incr(susp, &nn, cur)) goto out;
            }
            togo = MIN(nn, togo);
        }

        n = togo;
        incr_reg = susp->incr;
        lvl_reg = susp->lvl;
        out_ptr_reg = out_ptr;
        if (n) do { /* the inner sample computation loop */
                *out_ptr_reg++ = (sample_type) lvl_reg;
                lvl_reg += incr_reg;;
            } while (--n); /* inner loop */

        susp->lvl += susp->incr * togo;
        out_ptr += togo;
        cnt += togo;
    } /* outer loop */

    /* test for termination */
    if (togo == 0 && cnt == 0) {
        snd_list_terminate(snd_list);
    } else {
        snd_list->block_len = cnt;
        susp->susp.current += cnt;
    }
} /* pwl__fetch */
示例#4
0
void fromobject__fetch(register fromobject_susp_type susp, snd_list_type snd_list)
{
    int cnt = 0; /* how many samples computed */
    int togo;
    int n;
    sample_block_type out;
    register sample_block_values_type out_ptr;

    register sample_block_values_type out_ptr_reg;

    register boolean done_reg;
    register LVAL src_reg;
    falloc_sample_block(out, "fromobject__fetch");
    out_ptr = out->samples;
    snd_list->block = out;

    while (cnt < max_sample_block_len) { /* outer loop */
	/* first compute how many samples to generate in inner loop: */
	/* don't overflow the output sample block: */
	togo = max_sample_block_len - cnt;

        if (susp->done) {
            togo = 0; /* indicate termination */
            break;    /* we're done */
        }

	n = togo;
	done_reg = susp->done;
	src_reg = susp->src;
	out_ptr_reg = out_ptr;
	if (n) do { /* the inner sample computation loop */
            LVAL rslt = xleval(cons(s_send, cons(src_reg,
                                                 consa(s_next))));
            if (floatp(rslt)) {
                *out_ptr_reg++ = (sample_type) getflonum(rslt);
            } else {
                done_reg = true;
                /* adjust togo to what it should have been */
                break;
            };
	} while (--n); /* inner loop */

	togo -= n;
	susp->done = done_reg;
	out_ptr += togo;
	cnt += togo;
    } /* outer loop */

    /* test for termination */
    if (togo == 0 && cnt == 0) {
	snd_list_terminate(snd_list);
    } else {
	snd_list->block_len = cnt;
	susp->susp.current += cnt;
    }
} /* fromobject__fetch */
示例#5
0
void slider__fetch(snd_susp_type a_susp, snd_list_type snd_list)
{
    slider_susp_type susp = (slider_susp_type) a_susp;
    int cnt = 0; /* how many samples computed */
    int togo;
    int n;
    sample_block_type out;
    register sample_block_values_type out_ptr;

    register sample_block_values_type out_ptr_reg;

    register sample_type c_reg;
    int limit = ((long) susp->susp.sr) / 50;
    falloc_sample_block(out, "slider__fetch");
    out_ptr = out->samples;
    snd_list->block = out;

    /* compute no more than 20ms to preserve some interactivity */
    if (limit < 1) limit = 1;
    if (limit > max_sample_block_len) limit = max_sample_block_len;

    while (cnt < limit) { /* outer loop */
        /* first compute how many samples to generate in inner loop: */
        /* don't overflow the output sample block: */
        togo = limit - cnt;

        /* don't run past terminate time */
        if (susp->terminate_cnt != UNKNOWN &&
            susp->terminate_cnt <= susp->susp.current + cnt + togo) {
            togo = susp->terminate_cnt - (susp->susp.current + cnt);
            if (togo == 0) break;
        }

        n = togo;
        c_reg = slider_array[susp->index];
        out_ptr_reg = out_ptr;
        if (n) do { /* the inner sample computation loop */
            *out_ptr_reg++ = c_reg;
        } while (--n); /* inner loop */

        out_ptr += togo;
        cnt += togo;
    } /* outer loop */
    /* printf("slider %d cnt %d\n", susp->index, cnt); */
    /* test for termination */
    if (togo == 0 && cnt == 0) {
        snd_list_terminate(snd_list);
    } else {
        snd_list->block_len = cnt;
        susp->susp.current += cnt;
    }
} /* slider__fetch */
示例#6
0
void sine__fetch(register sine_susp_type susp, snd_list_type snd_list)
{
    int cnt = 0; /* how many samples computed */
    int togo;
    int n;
    sample_block_type out;
    register sample_block_values_type out_ptr;

    register sample_block_values_type out_ptr_reg;

    register long phase_reg;
    register long ph_incr_reg;
    falloc_sample_block(out, "sine__fetch");
    out_ptr = out->samples;
    snd_list->block = out;

    while (cnt < max_sample_block_len) { /* outer loop */
    /* first compute how many samples to generate in inner loop: */
    /* don't overflow the output sample block: */
    togo = max_sample_block_len - cnt;

    /* don't run past terminate time */
    if (susp->terminate_cnt != UNKNOWN &&
        susp->terminate_cnt <= susp->susp.current + cnt + togo) {
        togo = susp->terminate_cnt - (susp->susp.current + cnt);
        if (togo == 0) break;
    }

    n = togo;
    phase_reg = susp->phase;
    ph_incr_reg = susp->ph_incr;
    out_ptr_reg = out_ptr;
    if (n) do { /* the inner sample computation loop */
*out_ptr_reg++ = sine_table[phase_reg >> SINE_TABLE_SHIFT];
        phase_reg += ph_incr_reg;
        phase_reg &= SINE_TABLE_MASK;;
    } while (--n); /* inner loop */

    susp->phase = (susp->phase + susp->ph_incr * togo) & SINE_TABLE_MASK;
    out_ptr += togo;
    cnt += togo;
    } /* outer loop */

    /* test for termination */
    if (togo == 0 && cnt == 0) {
    snd_list_terminate(snd_list);
    } else {
    snd_list->block_len = cnt;
    susp->susp.current += cnt;
    }
} /* sine__fetch */
示例#7
0
void mandolin__fetch(register mandolin_susp_type susp, snd_list_type snd_list)
{
    int cnt = 0; /* how many samples computed */
    int togo;
    int n;
    sample_block_type out;
    register sample_block_values_type out_ptr;

    register sample_block_values_type out_ptr_reg;

    register struct instr * mymand_reg;
    falloc_sample_block(out, "mandolin__fetch");
    out_ptr = out->samples;
    snd_list->block = out;

    while (cnt < max_sample_block_len) { /* outer loop */
	/* first compute how many samples to generate in inner loop: */
	/* don't overflow the output sample block: */
	togo = max_sample_block_len - cnt;

	/* don't run past terminate time */
	if (susp->terminate_cnt != UNKNOWN &&
	    susp->terminate_cnt <= susp->susp.current + cnt + togo) {
	    togo = susp->terminate_cnt - (susp->susp.current + cnt);
	    if (togo == 0) break;
	}

	n = togo;
	mymand_reg = susp->mymand;
	out_ptr_reg = out_ptr;
	if (n) do { /* the inner sample computation loop */

	    *out_ptr_reg++ = (sample_type) tick(mymand_reg);
	} while (--n); /* inner loop */

	susp->mymand = mymand_reg;
	out_ptr += togo;
	cnt += togo;
    } /* outer loop */

    /* test for termination */
    if (togo == 0 && cnt == 0) {
	snd_list_terminate(snd_list);
    } else {
	snd_list->block_len = cnt;
	susp->susp.current += cnt;
    }
} /* mandolin__fetch */
示例#8
0
void white__fetch(snd_susp_type a_susp, snd_list_type snd_list)
{
    white_susp_type susp = (white_susp_type) a_susp;
    int cnt = 0; /* how many samples computed */
    int togo;
    int n;
    sample_block_type out;
    register sample_block_values_type out_ptr;

    register sample_block_values_type out_ptr_reg;

    falloc_sample_block(out, "white__fetch");
    out_ptr = out->samples;
    snd_list->block = out;

    while (cnt < max_sample_block_len) { /* outer loop */
	/* first compute how many samples to generate in inner loop: */
	/* don't overflow the output sample block: */
	togo = max_sample_block_len - cnt;

	/* don't run past terminate time */
	if (susp->terminate_cnt != UNKNOWN &&
	    susp->terminate_cnt <= susp->susp.current + cnt + togo) {
	    togo = susp->terminate_cnt - (susp->susp.current + cnt);
	    if (togo < 0) togo = 0;  /* avoids rounding errros */
	    if (togo == 0) break;
	}

	n = togo;
	out_ptr_reg = out_ptr;
	if (n) do { /* the inner sample computation loop */
            *out_ptr_reg++ = (sample_type) (rand() * rand_scale - 1.0);
	} while (--n); /* inner loop */

	out_ptr += togo;
	cnt += togo;
    } /* outer loop */

    /* test for termination */
    if (togo == 0 && cnt == 0) {
	snd_list_terminate(snd_list);
    } else {
	snd_list->block_len = cnt;
	susp->susp.current += cnt;
    }
} /* white__fetch */
示例#9
0
文件: sndread.c 项目: henricj/nyquist
void read__fetch(snd_susp_type a_susp, snd_list_type snd_list)
{
    read_susp_type susp = (read_susp_type) a_susp;
    long n; /* jlh Changed type to long, trying to make move_samples_... work */
    sample_block_type out;
    register sample_block_values_type out_ptr;
    /* allow up to 4 bytes/sample:  jlh -- does this need to be 8? */
    /* FIX -- why 8? for doubles? Maybe it should be sizeof(sample). I think
       this buffer was here to allow you to input any format and convert to
       float. The assumption was no sample would be longer than 4 bytes and
       after conversion, samples would be 4 byte floats. 
    */
    long in_count; /* jlh Trying to make move_samples_... work */

    falloc_sample_block(out, "read__fetch");
    out_ptr = out->samples;
    snd_list->block = out;

    in_count = sf_readf_float(susp->sndfile, out_ptr, max_sample_block_len);

    n = in_count;

    /* don't read too many */
    if (n > (susp->cnt - susp->susp.current)) {
        n = susp->cnt - susp->susp.current;
    }

    snd_list->block_len = (short) n;
    susp->susp.current += n;

    if (n == 0) {
        /* we didn't read anything, but can't return length zero, so
           convert snd_list to pointer to zero block */
        snd_list_terminate(snd_list);
    } else if (n < max_sample_block_len) {
        /* this should close file and free susp */
        snd_list_unref(snd_list->u.next);
        /* if something is in buffer, terminate by pointing to zero block */
        snd_list->u.next = zero_snd_list;
    }
} /* read__fetch */
示例#10
0
LOCAL void nyx_susp_fetch(register nyx_susp_type susp, snd_list_type snd_list)
{
   sample_block_type         out;
   sample_block_values_type  out_ptr;
   long                      n;
   int                       err;

   falloc_sample_block(out, "nyx_susp_fetch");
   out_ptr = out->samples;
   snd_list->block = out;

   n = max_sample_block_len;
   if (susp->susp.current + n > susp->len) {
      n = susp->len - susp->susp.current;
   }

   err = susp->callback(out_ptr, susp->channel,
                        susp->susp.current, n, 0, susp->userdata);
   if (err) {
      // The user canceled or some other error occurred, so we use
      // xlsignal() to jump back to our error handler.
      xlsignal(NULL, NULL);
      // never get here.
   }

   snd_list->block_len = (short)n;
   susp->susp.current += n;

   if (n == 0) {
      /* we didn't read anything, but can't return length zero, so
         convert snd_list to pointer to zero block */
      snd_list_terminate(snd_list);
   }
   else if (n < max_sample_block_len) {
      /* should free susp */
      snd_list_unref(snd_list->u.next);
      /* if something is in buffer, terminate by pointing to zero block */
      snd_list->u.next = zero_snd_list;
   }
}
示例#11
0
void fmosc_s_fetch(register fmosc_susp_type susp, snd_list_type snd_list)
{
    int cnt = 0; /* how many samples computed */
    int togo;
    int n;
    sample_block_type out;
    register sample_block_values_type out_ptr;

    register sample_block_values_type out_ptr_reg;

    register double table_len_reg;
    register double ph_incr_reg;
    register sample_type * table_ptr_reg;
    register double phase_reg;
    register sample_type s_fm_scale_reg = susp->s_fm->scale;
    register sample_block_values_type s_fm_ptr_reg;
    falloc_sample_block(out, "fmosc_s_fetch");
    out_ptr = out->samples;
    snd_list->block = out;

    while (cnt < max_sample_block_len) { /* outer loop */
    /* first compute how many samples to generate in inner loop: */
    /* don't overflow the output sample block: */
    togo = max_sample_block_len - cnt;

    /* don't run past the s_fm input sample block: */
    susp_check_term_log_samples(s_fm, s_fm_ptr, s_fm_cnt);
    togo = min(togo, susp->s_fm_cnt);

    /* don't run past terminate time */
    if (susp->terminate_cnt != UNKNOWN &&
        susp->terminate_cnt <= susp->susp.current + cnt + togo) {
        togo = susp->terminate_cnt - (susp->susp.current + cnt);
        if (togo == 0) break;
    }


    /* don't run past logical stop time */
    if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) {
        int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt);
        /* break if to_stop == 0 (we're at the logical stop)
         * AND cnt > 0 (we're not at the beginning of the
         * output block).
         */
        if (to_stop < togo) {
        if (to_stop == 0) {
            if (cnt) {
            togo = 0;
            break;
            } else /* keep togo as is: since cnt == 0, we
                    * can set the logical stop flag on this
                    * output block
                    */
            susp->logically_stopped = true;
        } else /* limit togo so we can start a new
                * block at the LST
                */
            togo = to_stop;
        }
    }

    n = togo;
    table_len_reg = susp->table_len;
    ph_incr_reg = susp->ph_incr;
    table_ptr_reg = susp->table_ptr;
    phase_reg = susp->phase;
    s_fm_ptr_reg = susp->s_fm_ptr;
    out_ptr_reg = out_ptr;
    if (n) do { /* the inner sample computation loop */
        long table_index;
        double x1;
table_index = (long) phase_reg;
        x1 = table_ptr_reg[table_index];
        *out_ptr_reg++ = (sample_type) (x1 + (phase_reg - table_index) * 
              (table_ptr_reg[table_index + 1] - x1));
        phase_reg += ph_incr_reg + (s_fm_scale_reg * *s_fm_ptr_reg++);
        while (phase_reg > table_len_reg) phase_reg -= table_len_reg;
        /* watch out for negative frequencies! */
        while (phase_reg < 0) phase_reg += table_len_reg;
    } while (--n); /* inner loop */

    susp->phase = phase_reg;
    /* using s_fm_ptr_reg is a bad idea on RS/6000: */
    susp->s_fm_ptr += togo;
    out_ptr += togo;
    susp_took(s_fm_cnt, togo);
    cnt += togo;
    } /* outer loop */

    /* test for termination */
    if (togo == 0 && cnt == 0) {
    snd_list_terminate(snd_list);
    } else {
    snd_list->block_len = cnt;
    susp->susp.current += cnt;
    }
    /* test for logical stop */
    if (susp->logically_stopped) {
    snd_list->logically_stopped = true;
    } else if (susp->susp.log_stop_cnt == susp->susp.current) {
    susp->logically_stopped = true;
    }
} /* fmosc_s_fetch */
示例#12
0
void up_r_fetch(register up_susp_type susp, snd_list_type snd_list)
{
    int cnt = 0; /* how many samples computed */
    sample_type input_DeLtA;
    sample_type input_val;
    sample_type input_x2_sample;
    int togo;
    int n;
    sample_block_type out;
    register sample_block_values_type out_ptr;

    register sample_block_values_type out_ptr_reg;

    falloc_sample_block(out, "up_r_fetch");
    out_ptr = out->samples;
    snd_list->block = out;

    /* make sure sounds are primed with first values */
    if (!susp->started) {
	susp->started = true;
	susp->input_pHaSe = 1.0;
    }

    susp_check_term_log_samples(input, input_ptr, input_cnt);
    input_x2_sample = susp_current_sample(input, input_ptr);

    while (cnt < max_sample_block_len) { /* outer loop */
	/* first compute how many samples to generate in inner loop: */
	/* don't overflow the output sample block: */
	togo = max_sample_block_len - cnt;

	/* grab next input_x2_sample when phase goes past 1.0; */
	/* we use input_n (computed below) to avoid roundoff errors: */
	if (susp->input_n <= 0) {
	    susp->input_x1_sample = input_x2_sample;
	    susp->input_ptr++;
	    susp_took(input_cnt, 1);
	    susp->input_pHaSe -= 1.0;
	    susp_check_term_log_samples(input, input_ptr, input_cnt);
	    input_x2_sample = susp_current_sample(input, input_ptr);
	    /* input_n gets number of samples before phase exceeds 1.0: */
	    susp->input_n = (long) ((1.0 - susp->input_pHaSe) *
					susp->output_per_input);
	}
	togo = MIN(togo, susp->input_n);
	input_DeLtA = (sample_type) ((input_x2_sample - susp->input_x1_sample) * susp->input_pHaSe_iNcR);
	input_val = (sample_type) (susp->input_x1_sample * (1.0 - susp->input_pHaSe) +
		 input_x2_sample * susp->input_pHaSe);

	/* don't run past terminate time */
	if (susp->terminate_cnt != UNKNOWN &&
	    susp->terminate_cnt <= susp->susp.current + cnt + togo) {
	    togo = susp->terminate_cnt - (susp->susp.current + cnt);
	    if (togo == 0) break;
	}


	/* don't run past logical stop time */
	if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) {
	    int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt);
	    /* break if to_stop == 0 (we're at the logical stop)
	     * AND cnt > 0 (we're not at the beginning of the
	     * output block).
	     */
	    if (to_stop < togo) {
		if (to_stop == 0) {
		    if (cnt) {
			togo = 0;
			break;
		    } else /* keep togo as is: since cnt == 0, we
		            * can set the logical stop flag on this
		            * output block
		            */
			susp->logically_stopped = true;
		} else /* limit togo so we can start a new
		        * block at the LST
		        */
		    togo = to_stop;
	    }
	}

	n = togo;
	out_ptr_reg = out_ptr;
	if (n) do { /* the inner sample computation loop */
*out_ptr_reg++ = (sample_type) input_val;
	    input_val += input_DeLtA;
	} while (--n); /* inner loop */

	out_ptr += togo;
	susp->input_pHaSe += togo * susp->input_pHaSe_iNcR;
	susp->input_n -= togo;
	cnt += togo;
    } /* outer loop */

    /* test for termination */
    if (togo == 0 && cnt == 0) {
	snd_list_terminate(snd_list);
    } else {
	snd_list->block_len = cnt;
	susp->susp.current += cnt;
    }
    /* test for logical stop */
    if (susp->logically_stopped) {
	snd_list->logically_stopped = true;
    } else if (susp->susp.log_stop_cnt == susp->susp.current) {
	susp->logically_stopped = true;
    }
} /* up_r_fetch */
示例#13
0
void atonev_nr_fetch(register atonev_susp_type susp, snd_list_type snd_list)
{
    int cnt = 0; /* how many samples computed */
    sample_type hz_val;
    int togo;
    int n;
    sample_block_type out;
    register sample_block_values_type out_ptr;

    register sample_block_values_type out_ptr_reg;

    register double cc_reg;
    register double prev_reg;
    register sample_block_values_type s1_ptr_reg;
    falloc_sample_block(out, "atonev_nr_fetch");
    out_ptr = out->samples;
    snd_list->block = out;

    /* make sure sounds are primed with first values */
    if (!susp->started) {
	susp->started = true;
	susp->hz_pHaSe = 1.0;
    }

    susp_check_term_samples(hz, hz_ptr, hz_cnt);

    while (cnt < max_sample_block_len) { /* outer loop */
	/* first compute how many samples to generate in inner loop: */
	/* don't overflow the output sample block: */
	togo = max_sample_block_len - cnt;

	/* don't run past the s1 input sample block: */
	susp_check_term_log_samples(s1, s1_ptr, s1_cnt);
	togo = min(togo, susp->s1_cnt);

	/* grab next hz_x1_sample when phase goes past 1.0; */
	/* use hz_n (computed below) to avoid roundoff errors: */
	if (susp->hz_n <= 0) {
	    register double bb;
	    susp_check_term_samples(hz, hz_ptr, hz_cnt);
	    susp->hz_x1_sample = susp_fetch_sample(hz, hz_ptr, hz_cnt);
	    susp->hz_pHaSe -= 1.0;
	    /* hz_n gets number of samples before phase exceeds 1.0: */
	    susp->hz_n = (long) ((1.0 - susp->hz_pHaSe) *
					susp->output_per_hz);
	    bb = 2.0 - cos(susp->hz_x1_sample);
	    susp->cc = bb - sqrt((bb * bb) - 1.0);
	}
	togo = min(togo, susp->hz_n);
	hz_val = susp->hz_x1_sample;
	/* don't run past terminate time */
	if (susp->terminate_cnt != UNKNOWN &&
	    susp->terminate_cnt <= susp->susp.current + cnt + togo) {
	    togo = susp->terminate_cnt - (susp->susp.current + cnt);
	    if (togo == 0) break;
	}


	/* don't run past logical stop time */
	if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) {
	    int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt);
	    /* break if to_stop == 0 (we're at the logical stop)
	     * AND cnt > 0 (we're not at the beginning of the
	     * output block).
	     */
	    if (to_stop < togo) {
		if (to_stop == 0) {
		    if (cnt) {
			togo = 0;
			break;
		    } else /* keep togo as is: since cnt == 0, we
		            * can set the logical stop flag on this
		            * output block
		            */
			susp->logically_stopped = true;
		} else /* limit togo so we can start a new
		        * block at the LST
		        */
		    togo = to_stop;
	    }
	}

	n = togo;
	cc_reg = susp->cc;
	prev_reg = susp->prev;
	s1_ptr_reg = susp->s1_ptr;
	out_ptr_reg = out_ptr;
	if (n) do { /* the inner sample computation loop */
        double current;
current = *s1_ptr_reg++;
            prev_reg = cc_reg * (prev_reg + current);
            *out_ptr_reg++ = (sample_type) prev_reg;
            prev_reg -= current;;
	} while (--n); /* inner loop */

	susp->prev = prev_reg;
	/* using s1_ptr_reg is a bad idea on RS/6000: */
	susp->s1_ptr += togo;
	out_ptr += togo;
	susp_took(s1_cnt, togo);
	susp->hz_pHaSe += togo * susp->hz_pHaSe_iNcR;
	susp->hz_n -= togo;
	cnt += togo;
    } /* outer loop */

    /* test for termination */
    if (togo == 0 && cnt == 0) {
	snd_list_terminate(snd_list);
    } else {
	snd_list->block_len = cnt;
	susp->susp.current += cnt;
    }
    /* test for logical stop */
    if (susp->logically_stopped) {
	snd_list->logically_stopped = true;
    } else if (susp->susp.log_stop_cnt == susp->susp.current) {
	susp->logically_stopped = true;
    }
} /* atonev_nr_fetch */
示例#14
0
void clip_s_fetch(snd_susp_type a_susp, snd_list_type snd_list)
{
    clip_susp_type susp = (clip_susp_type) a_susp;
    int cnt = 0; /* how many samples computed */
    int togo;
    int n;
    sample_block_type out;
    register sample_block_values_type out_ptr;

    register sample_block_values_type out_ptr_reg;

    register sample_type level_reg;
    register sample_type s_scale_reg = susp->s->scale;
    register sample_block_values_type s_ptr_reg;
    falloc_sample_block(out, "clip_s_fetch");
    out_ptr = out->samples;
    snd_list->block = out;

    while (cnt < max_sample_block_len) { /* outer loop */
	/* first compute how many samples to generate in inner loop: */
	/* don't overflow the output sample block: */
	togo = max_sample_block_len - cnt;

	/* don't run past the s input sample block: */
	susp_check_term_log_samples(s, s_ptr, s_cnt);
	togo = min(togo, susp->s_cnt);

	/* don't run past terminate time */
	if (susp->terminate_cnt != UNKNOWN &&
	    susp->terminate_cnt <= susp->susp.current + cnt + togo) {
	    togo = susp->terminate_cnt - (susp->susp.current + cnt);
	    if (togo < 0) togo = 0;  /* avoids rounding errros */
	    if (togo == 0) break;
	}


	/* don't run past logical stop time */
	if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) {
	    int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt);
	    /* break if to_stop == 0 (we're at the logical stop)
	     * AND cnt > 0 (we're not at the beginning of the
	     * output block).
	     */
	    if (to_stop < 0) to_stop = 0; /* avoids rounding errors */
	    if (to_stop < togo) {
		if (to_stop == 0) {
		    if (cnt) {
			togo = 0;
			break;
		    } else /* keep togo as is: since cnt == 0, we
		            * can set the logical stop flag on this
		            * output block
		            */
			susp->logically_stopped = true;
		} else /* limit togo so we can start a new
		        * block at the LST
		        */
		    togo = to_stop;
	    }
	}

	n = togo;
	level_reg = susp->level;
	s_ptr_reg = susp->s_ptr;
	out_ptr_reg = out_ptr;
	if (n) do { /* the inner sample computation loop */
            double x = (s_scale_reg * *s_ptr_reg++); 
            *out_ptr_reg++ = (sample_type) 
            (x > level_reg ? 
             level_reg : (x < -level_reg ? -level_reg : x));
	} while (--n); /* inner loop */

	susp->level = level_reg;
	/* using s_ptr_reg is a bad idea on RS/6000: */
	susp->s_ptr += togo;
	out_ptr += togo;
	susp_took(s_cnt, togo);
	cnt += togo;
    } /* outer loop */

    /* test for termination */
    if (togo == 0 && cnt == 0) {
	snd_list_terminate(snd_list);
    } else {
	snd_list->block_len = cnt;
	susp->susp.current += cnt;
    }
    /* test for logical stop */
    if (susp->logically_stopped) {
	snd_list->logically_stopped = true;
    } else if (susp->susp.log_stop_cnt == susp->susp.current) {
	susp->logically_stopped = true;
    }
} /* clip_s_fetch */
示例#15
0
void up_i_fetch(register up_susp_type susp, snd_list_type snd_list)
{
    int cnt = 0; /* how many samples computed */
    sample_type input_x2_sample;
    int togo;
    int n;
    sample_block_type out;
    register sample_block_values_type out_ptr;

    register sample_block_values_type out_ptr_reg;

    register double input_pHaSe_iNcR_rEg = susp->input_pHaSe_iNcR;
    register double input_pHaSe_ReG;
    register sample_type input_x1_sample_reg;
    falloc_sample_block(out, "up_i_fetch");
    out_ptr = out->samples;
    snd_list->block = out;

    /* make sure sounds are primed with first values */
    if (!susp->started) {
	susp->started = true;
	susp_check_term_log_samples(input, input_ptr, input_cnt);
	susp->input_x1_sample = susp_fetch_sample(input, input_ptr, input_cnt);
    }

    susp_check_term_log_samples(input, input_ptr, input_cnt);
    input_x2_sample = susp_current_sample(input, input_ptr);

    while (cnt < max_sample_block_len) { /* outer loop */
	/* first compute how many samples to generate in inner loop: */
	/* don't overflow the output sample block: */
	togo = max_sample_block_len - cnt;

	/* don't run past terminate time */
	if (susp->terminate_cnt != UNKNOWN &&
	    susp->terminate_cnt <= susp->susp.current + cnt + togo) {
	    togo = susp->terminate_cnt - (susp->susp.current + cnt);
	    if (togo == 0) break;
	}


	/* don't run past logical stop time */
	if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) {
	    int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt);
	    /* break if to_stop == 0 (we're at the logical stop)
	     * AND cnt > 0 (we're not at the beginning of the
	     * output block).
	     */
	    if (to_stop < togo) {
		if (to_stop == 0) {
		    if (cnt) {
			togo = 0;
			break;
		    } else /* keep togo as is: since cnt == 0, we
		            * can set the logical stop flag on this
		            * output block
		            */
			susp->logically_stopped = true;
		} else /* limit togo so we can start a new
		        * block at the LST
		        */
		    togo = to_stop;
	    }
	}

	n = togo;
	input_pHaSe_ReG = susp->input_pHaSe;
	input_x1_sample_reg = susp->input_x1_sample;
	out_ptr_reg = out_ptr;
	if (n) do { /* the inner sample computation loop */
	    if (input_pHaSe_ReG >= 1.0) {
		input_x1_sample_reg = input_x2_sample;
		/* pick up next sample as input_x2_sample: */
		susp->input_ptr++;
		susp_took(input_cnt, 1);
		input_pHaSe_ReG -= 1.0;
		susp_check_term_log_samples_break(input, input_ptr, input_cnt, input_x2_sample);
	    }
*out_ptr_reg++ = (sample_type) 
		(input_x1_sample_reg * (1 - input_pHaSe_ReG) + input_x2_sample * input_pHaSe_ReG);
	    input_pHaSe_ReG += input_pHaSe_iNcR_rEg;
	} while (--n); /* inner loop */

	togo -= n;
	susp->input_pHaSe = input_pHaSe_ReG;
	susp->input_x1_sample = input_x1_sample_reg;
	out_ptr += togo;
	cnt += togo;
    } /* outer loop */

    /* test for termination */
    if (togo == 0 && cnt == 0) {
	snd_list_terminate(snd_list);
    } else {
	snd_list->block_len = cnt;
	susp->susp.current += cnt;
    }
    /* test for logical stop */
    if (susp->logically_stopped) {
	snd_list->logically_stopped = true;
    } else if (susp->susp.log_stop_cnt == susp->susp.current) {
	susp->logically_stopped = true;
    }
} /* up_i_fetch */
示例#16
0
文件: yin.c 项目: AaronFae/VimProject
/*
 * The pitch (F0) is determined by finding two periods whose
 * inner product accounts for almost all of the energy. Let X and Y
 * be adjacent vectors of length N in the sample stream. Then, 
 *    if 2X*Y > threshold * (X*X + Y*Y)
 *    then the period is given by N
 * In the algorithm, we compute different sizes until we find a
 * peak above threshold. Then, we use cubic interpolation to get
 * a precise value. If no peak above threshold is found, we return
 * the first peak. The second channel returns the value 2X*Y/(X*X+Y*Y)
 * which is refered to as the "harmonicity" -- the amount of energy
 * accounted for by periodicity.
 *
 * Low sample rates are advised because of the high cost of computing
 * inner products (fast autocorrelation is not used).
 *
 * The result is a 2-channel signal running at the requested rate.
 * The first channel is the estimated pitch, and the second channel
 * is the harmonicity.
 *
 * This code is adopted from multiread, currently the only other
 * multichannel suspension in Nyquist. Comments from multiread include:
 * The susp is shared by all channels.  The susp has backpointers
 * to the tail-most snd_list node of each channel, and it is by
 * extending the list at these nodes that sounds are read in.
 * To avoid a circularity, the reference counts on snd_list nodes
 * do not include the backpointers from this susp.  When a snd_list
 * node refcount goes to zero, the yin susp's free routine
 * is called.  This must scan the backpointers to find the node that
 * has a zero refcount (the free routine is called before the node
 * is deallocated, so this is safe).  The backpointer is then set
 * to NULL.  When all backpointers are NULL, the susp itself is
 * deallocated, because it can only be referenced through the
 * snd_list nodes to which there are backpointers.
 */
void yin_fetch(yin_susp_type susp, snd_list_type snd_list)
{
    int cnt = 0; /* how many samples computed */
    int togo = 0;
    int n;
    sample_block_type f0;
    sample_block_values_type f0_ptr = NULL;
    sample_block_type harmonicity;
    sample_block_values_type harmonicity_ptr = NULL;

    register sample_block_values_type s_ptr_reg;
    register sample_type *fillptr_reg;
    register sample_type *endptr_reg = susp->endptr;

    if (susp->chan[0]) {
        falloc_sample_block(f0, "yin_fetch");
        f0_ptr = f0->samples;
        /* Since susp->chan[i] exists, we want to append a block of samples.
         * The block, out, has been allocated.  Before we insert the block,
         * we must figure out whether to insert a new snd_list_type node for
         * the block.  Recall that before SND_get_next is called, the last
         * snd_list_type in the list will have a null block pointer, and the
         * snd_list_type's susp field points to the suspension (in this case,
         * susp).  When SND_get_next (in sound.c) is called, it appends a new
         * snd_list_type and points the previous one to internal_zero_block 
         * before calling this fetch routine.  On the other hand, since 
         * SND_get_next is only going to be called on one of the channels, the
         * other channels will not have had a snd_list_type appended.
         * SND_get_next does not tell us directly which channel it wants (it
         * doesn't know), but we can test by looking for a non-null block in the
         * snd_list_type pointed to by our back-pointers in susp->chan[].  If
         * the block is null, the channel was untouched by SND_get_next, and
         * we should append a snd_list_type.  If it is non-null, then it
         * points to internal_zero_block (the block inserted by SND_get_next)
         * and a new snd_list_type has already been appended.
         */
        /* Before proceeding, it may be that garbage collection ran when we
         * allocated out, so check again to see if susp->chan[j] is Null:
         */
        if (!susp->chan[0]) {
            ffree_sample_block(f0, "yin_fetch");
            f0 = NULL; /* make sure we don't free it again */
            f0_ptr = NULL; /* make sure we don't output f0 samples */
        } else if (!susp->chan[0]->block) {
            snd_list_type snd_list = snd_list_create((snd_susp_type) susp);
            /* Now we have a snd_list to append to the channel, but a very
             * interesting thing can happen here.  snd_list_create, which
             * we just called, MAY have invoked the garbage collector, and
             * the GC MAY have freed all references to this channel, in which
             * case yin_free(susp) will have been called, and susp->chan[0]
             * will now be NULL!
             */
            if (!susp->chan[0]) {
                ffree_snd_list(snd_list, "yin_fetch");
            } else {
                susp->chan[0]->u.next = snd_list;
            }
        }
        /* see the note above: we don't know if susp->chan still exists */
        /* Note: We DO know that susp still exists because even if we lost
         * some channels in a GC, someone is still calling SND_get_next on
         * some channel.  I suppose that there might be some very pathological
         * code that could free a global reference to a sound that is in the
         * midst of being computed, perhaps by doing something bizarre in the
         * closure that snd_seq activates at the logical stop time of its first
         * sound, but I haven't thought that one through.
         */
        if (susp->chan[0]) {
            susp->chan[0]->block = f0;
            /* check some assertions */
            if (susp->chan[0]->u.next->u.susp != (snd_susp_type) susp) {
                nyquist_printf("didn't find susp at end of list for chan 0\n");
            }
        } else if (f0) { /* we allocated f0, but don't need it anymore due to GC */
            ffree_sample_block(f0, "yin_fetch");
            f0_ptr = NULL;
        }
    }

    /* Now, repeat for channel 1 (comments omitted) */
    if (susp->chan[1]) {
        falloc_sample_block(harmonicity, "yin_fetch");
        harmonicity_ptr = harmonicity->samples;
        if (!susp->chan[1]) {
            ffree_sample_block(harmonicity, "yin_fetch");
            harmonicity = NULL; /* make sure we don't free it again */
            harmonicity_ptr = NULL;
        } else if (!susp->chan[1]->block) {
            snd_list_type snd_list = snd_list_create((snd_susp_type) susp);
            if (!susp->chan[1]) {
                ffree_snd_list(snd_list, "yin_fetch");
            } else {
                susp->chan[1]->u.next = snd_list;
            }
        }
        if (susp->chan[1]) {
            susp->chan[1]->block = harmonicity;
            if (susp->chan[1]->u.next->u.susp != (snd_susp_type) susp) {
                nyquist_printf("didn't find susp at end of list for chan 1\n");
            }
        } else if (harmonicity) { /* we allocated harmonicity, but don't need it anymore due to GC */
            ffree_sample_block(harmonicity, "yin_fetch");
            harmonicity_ptr = NULL;
        }
    }

    while (cnt < max_sample_block_len) { /* outer loop */
        /* first, compute how many samples to generate in inner loop: */
        /* don't overflow the output sample block */
        togo = (max_sample_block_len - cnt) * susp->stepsize;

        /* don't run past the s input sample block */
        susp_check_term_log_samples(s, s_ptr, s_cnt);
        togo = min(togo, susp->s_cnt);

        /* don't run past terminate time */
        if (susp->terminate_cnt != UNKNOWN &&
            susp->terminate_cnt <= susp->susp.current + cnt + togo/susp->stepsize) {
            togo = (susp->terminate_cnt - (susp->susp.current + cnt)) * susp->stepsize;
            if (togo == 0) break;
        }

        /* don't run past logical stop time */
        if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) {
            int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt);
            /* break if to_stop = 0 (we're at the logical stop)
             * AND cnt > 0 (we're not at the beginning of the output block)
             */
            if (to_stop < togo/susp->stepsize) {
                if (to_stop == 0) {
                    if (cnt) {
                        togo = 0;
                        break;
                    } else /* keep togo as is: since cnt == 0, we can set
                            * the logical stop flag on this output block
                            */
                        susp->logically_stopped = true;
                } else /* limit togo so we can start a new block a the LST */
                    togo = to_stop * susp->stepsize;
            }
        }
        n = togo;
        s_ptr_reg = susp->s_ptr;
        fillptr_reg = susp->fillptr;
        if (n) do { /* the inner sample computation loop */
            *fillptr_reg++ = *s_ptr_reg++;
            if (fillptr_reg >= endptr_reg) {
                float f0;
                float harmonicity;
                yin_compute(susp, &f0, &harmonicity);
                if (f0_ptr) *f0_ptr++ = f0;
                if (harmonicity_ptr) *harmonicity_ptr++ = harmonicity;
                cnt++;
                fillptr_reg -= susp->stepsize;
            }
        } while (--n); /* inner loop */

        /* using s_ptr_reg is a bad idea on RS/6000: */
        susp->s_ptr += togo;
        susp->fillptr = fillptr_reg;
        susp_took(s_cnt, togo);
    } /* outer loop */

    /* test for termination */
    if (togo == 0 && cnt == 0) {
        snd_list_terminate(snd_list);
    } else {
        snd_list->block_len = cnt;
        susp->susp.current += cnt;
    }

    /* test for logical stop */
    if (susp->logically_stopped) {
        snd_list->logically_stopped = true;
    } else if (susp->susp.log_stop_cnt == susp->susp.current) {
        susp->logically_stopped = true;
    }
} /* yin_fetch */
示例#17
0
void follow_s_fetch(snd_susp_type a_susp, snd_list_type snd_list)
{
    follow_susp_type susp = (follow_susp_type) a_susp;
    int cnt = 0; /* how many samples computed */
    int togo;
    int n;
    sample_block_type out;
    register sample_block_values_type out_ptr;

    register sample_block_values_type out_ptr_reg;

    register long lookahead_reg;
    register sample_type * delayptr_reg;
    register sample_type * prevptr_reg;
    register sample_type * endptr_reg;
    register double floor_reg;
    register double rise_factor_reg;
    register double fall_factor_reg;
    register sample_type sndin_scale_reg = susp->sndin->scale;
    register sample_block_values_type sndin_ptr_reg;
    falloc_sample_block(out, "follow_s_fetch");
    out_ptr = out->samples;
    snd_list->block = out;

    while (cnt < max_sample_block_len) { /* outer loop */
	/* first compute how many samples to generate in inner loop: */
	/* don't overflow the output sample block: */
	togo = max_sample_block_len - cnt;

	/* don't run past the sndin input sample block: */
	susp_check_term_samples(sndin, sndin_ptr, sndin_cnt);
	togo = min(togo, susp->sndin_cnt);

	/* don't run past terminate time */
	if (susp->terminate_cnt != UNKNOWN &&
	    susp->terminate_cnt <= susp->susp.current + cnt + togo) {
	    togo = susp->terminate_cnt - (susp->susp.current + cnt);
	    if (togo < 0) togo = 0;  /* avoids rounding errros */
	    if (togo == 0) break;
	}

	n = togo;
	lookahead_reg = susp->lookahead;
	delayptr_reg = susp->delayptr;
	prevptr_reg = susp->prevptr;
	endptr_reg = susp->endptr;
	floor_reg = susp->floor;
	rise_factor_reg = susp->rise_factor;
	fall_factor_reg = susp->fall_factor;
	sndin_ptr_reg = susp->sndin_ptr;
	out_ptr_reg = out_ptr;
	if (n) do { /* the inner sample computation loop */
            sample_type current = (sndin_scale_reg * *sndin_ptr_reg++);
            sample_type high = (sample_type) (*prevptr_reg * rise_factor_reg);
            sample_type low = (sample_type) (*prevptr_reg * fall_factor_reg);
            if (low < floor_reg) low = (sample_type) floor_reg;
            if (current < low) *delayptr_reg = (sample_type) low;
            else if (current < high) *delayptr_reg = current;
            else /* current > high */ {
                /* work back from current */
                double rise_inverse = 1.0 / rise_factor_reg;
                double temp = current * rise_inverse;
                boolean ok = false;
                sample_type *ptr = prevptr_reg;
                int i;
                               
                for (i = 0; i < lookahead_reg - 2; i++) {
                    if (*ptr < temp) {
                    *ptr-- = (sample_type) temp;
                    temp *= rise_inverse;
                    if (ptr < susp->delaybuf)
                        ptr = endptr_reg - 1;
                    } else {
                        ok = true;
                        break;
                    }
                }
                if (!ok && (*ptr < temp)) {
                    temp = *ptr;
                    for (i = 0; i < lookahead_reg - 1; i++) {
                        ptr++;
                        if (ptr == endptr_reg) ptr = susp->delaybuf;
                        temp *= rise_factor_reg;
                        *ptr = (sample_type) temp;
                    }
                } else *delayptr_reg = current;
            }
            prevptr_reg = delayptr_reg++;
            if (delayptr_reg == endptr_reg) delayptr_reg = susp->delaybuf;
            *out_ptr_reg++ = *delayptr_reg;
	} while (--n); /* inner loop */

	togo -= n;
	susp->lookahead = lookahead_reg;
	susp->delayptr = delayptr_reg;
	susp->prevptr = prevptr_reg;
	susp->floor = floor_reg;
	/* using sndin_ptr_reg is a bad idea on RS/6000: */
	susp->sndin_ptr += togo;
	out_ptr += togo;
	susp_took(sndin_cnt, togo);
	cnt += togo;
    } /* outer loop */

    /* test for termination */
    if (togo == 0 && cnt == 0) {
	snd_list_terminate(snd_list);
    } else {
	snd_list->block_len = cnt;
	susp->susp.current += cnt;
    }
} /* follow_s_fetch */
示例#18
0
void atonev_ns_fetch(register atonev_susp_type susp, snd_list_type snd_list)
{
    int cnt = 0; /* how many samples computed */
    int togo;
    int n;
    sample_block_type out;
    register sample_block_values_type out_ptr;

    register sample_block_values_type out_ptr_reg;

    register double cc_reg;
    register double prev_reg;
    register sample_type hz_scale_reg = susp->hz->scale;
    register sample_block_values_type hz_ptr_reg;
    register sample_block_values_type s1_ptr_reg;
    falloc_sample_block(out, "atonev_ns_fetch");
    out_ptr = out->samples;
    snd_list->block = out;

    while (cnt < max_sample_block_len) { /* outer loop */
	/* first compute how many samples to generate in inner loop: */
	/* don't overflow the output sample block: */
	togo = max_sample_block_len - cnt;

	/* don't run past the s1 input sample block: */
	susp_check_term_log_samples(s1, s1_ptr, s1_cnt);
	togo = min(togo, susp->s1_cnt);

	/* don't run past the hz input sample block: */
	susp_check_term_samples(hz, hz_ptr, hz_cnt);
	togo = min(togo, susp->hz_cnt);

	/* don't run past terminate time */
	if (susp->terminate_cnt != UNKNOWN &&
	    susp->terminate_cnt <= susp->susp.current + cnt + togo) {
	    togo = susp->terminate_cnt - (susp->susp.current + cnt);
	    if (togo == 0) break;
	}


	/* don't run past logical stop time */
	if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) {
	    int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt);
	    /* break if to_stop == 0 (we're at the logical stop)
	     * AND cnt > 0 (we're not at the beginning of the
	     * output block).
	     */
	    if (to_stop < togo) {
		if (to_stop == 0) {
		    if (cnt) {
			togo = 0;
			break;
		    } else /* keep togo as is: since cnt == 0, we
		            * can set the logical stop flag on this
		            * output block
		            */
			susp->logically_stopped = true;
		} else /* limit togo so we can start a new
		        * block at the LST
		        */
		    togo = to_stop;
	    }
	}

	n = togo;
	cc_reg = susp->cc;
	prev_reg = susp->prev;
	hz_ptr_reg = susp->hz_ptr;
	s1_ptr_reg = susp->s1_ptr;
	out_ptr_reg = out_ptr;
	if (n) do { /* the inner sample computation loop */
        double current;
	    register double bb;
	    bb = 2.0 - cos((hz_scale_reg * *hz_ptr_reg++));
	    cc_reg = bb - sqrt((bb * bb) - 1.0);
current = *s1_ptr_reg++;
            prev_reg = cc_reg * (prev_reg + current);
            *out_ptr_reg++ = (sample_type) prev_reg;
            prev_reg -= current;;
	} while (--n); /* inner loop */

	susp->prev = prev_reg;
	/* using hz_ptr_reg is a bad idea on RS/6000: */
	susp->hz_ptr += togo;
	/* using s1_ptr_reg is a bad idea on RS/6000: */
	susp->s1_ptr += togo;
	out_ptr += togo;
	susp_took(s1_cnt, togo);
	susp_took(hz_cnt, togo);
	cnt += togo;
    } /* outer loop */

    /* test for termination */
    if (togo == 0 && cnt == 0) {
	snd_list_terminate(snd_list);
    } else {
	snd_list->block_len = cnt;
	susp->susp.current += cnt;
    }
    /* test for logical stop */
    if (susp->logically_stopped) {
	snd_list->logically_stopped = true;
    } else if (susp->susp.log_stop_cnt == susp->susp.current) {
	susp->logically_stopped = true;
    }
} /* atonev_ns_fetch */
示例#19
0
void aresonvc_ns_fetch(register aresonvc_susp_type susp, snd_list_type snd_list)
{
    int cnt = 0; /* how many samples computed */
    int togo;
    int n;
    sample_block_type out;
    register sample_block_values_type out_ptr;

    register sample_block_values_type out_ptr_reg;

    register double c3co_reg;
    register double c3p1_reg;
    register double c3t4_reg;
    register double omc3_reg;
    register double c2_reg;
    register double c1_reg;
    register int normalization_reg;
    register double y1_reg;
    register double y2_reg;
    register sample_type hz_scale_reg = susp->hz->scale;
    register sample_block_values_type hz_ptr_reg;
    register sample_block_values_type s1_ptr_reg;
    falloc_sample_block(out, "aresonvc_ns_fetch");
    out_ptr = out->samples;
    snd_list->block = out;

    while (cnt < max_sample_block_len) { /* outer loop */
    /* first compute how many samples to generate in inner loop: */
    /* don't overflow the output sample block: */
    togo = max_sample_block_len - cnt;

    /* don't run past the s1 input sample block: */
    susp_check_term_log_samples(s1, s1_ptr, s1_cnt);
    togo = min(togo, susp->s1_cnt);

    /* don't run past the hz input sample block: */
    susp_check_term_samples(hz, hz_ptr, hz_cnt);
    togo = min(togo, susp->hz_cnt);

    /* don't run past terminate time */
    if (susp->terminate_cnt != UNKNOWN &&
        susp->terminate_cnt <= susp->susp.current + cnt + togo) {
        togo = susp->terminate_cnt - (susp->susp.current + cnt);
        if (togo == 0) break;
    }


    /* don't run past logical stop time */
    if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) {
        int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt);
        /* break if to_stop == 0 (we're at the logical stop)
         * AND cnt > 0 (we're not at the beginning of the
         * output block).
         */
        if (to_stop < togo) {
        if (to_stop == 0) {
            if (cnt) {
            togo = 0;
            break;
            } else /* keep togo as is: since cnt == 0, we
                    * can set the logical stop flag on this
                    * output block
                    */
            susp->logically_stopped = true;
        } else /* limit togo so we can start a new
                * block at the LST
                */
            togo = to_stop;
        }
    }

    n = togo;
    c3co_reg = susp->c3co;
    c3p1_reg = susp->c3p1;
    c3t4_reg = susp->c3t4;
    omc3_reg = susp->omc3;
    c2_reg = susp->c2;
    c1_reg = susp->c1;
    normalization_reg = susp->normalization;
    y1_reg = susp->y1;
    y2_reg = susp->y2;
    hz_ptr_reg = susp->hz_ptr;
    s1_ptr_reg = susp->s1_ptr;
    out_ptr_reg = out_ptr;
    if (n) do { /* the inner sample computation loop */
            register double y0, current;	    c2_reg = c3t4_reg * cos((hz_scale_reg * *hz_ptr_reg++)) / c3p1_reg;
        c1_reg = (normalization_reg == 0 ? 0.0 :
      (normalization_reg == 1 ? 1.0 - omc3_reg * sqrt(1.0 - c2_reg * c2_reg / c3t4_reg) :
          1.0 - sqrt(c3p1_reg * c3p1_reg - c2_reg * c2_reg) * omc3_reg / c3p1_reg));
current = *s1_ptr_reg++;
        y0 = c1_reg * current + c2_reg * y1_reg - c3co_reg * y2_reg;
        *out_ptr_reg++ = (sample_type) y0;
        y2_reg = y1_reg; y1_reg = y0 - current;
    } while (--n); /* inner loop */

    susp->y1 = y1_reg;
    susp->y2 = y2_reg;
    /* using hz_ptr_reg is a bad idea on RS/6000: */
    susp->hz_ptr += togo;
    /* using s1_ptr_reg is a bad idea on RS/6000: */
    susp->s1_ptr += togo;
    out_ptr += togo;
    susp_took(s1_cnt, togo);
    susp_took(hz_cnt, togo);
    cnt += togo;
    } /* outer loop */

    /* test for termination */
    if (togo == 0 && cnt == 0) {
    snd_list_terminate(snd_list);
    } else {
    snd_list->block_len = cnt;
    susp->susp.current += cnt;
    }
    /* test for logical stop */
    if (susp->logically_stopped) {
    snd_list->logically_stopped = true;
    } else if (susp->susp.log_stop_cnt == susp->susp.current) {
    susp->logically_stopped = true;
    }
} /* aresonvc_ns_fetch */
示例#20
0
void delaycv_nn_fetch(register delaycv_susp_type susp, snd_list_type snd_list)
{
    int cnt = 0; /* how many samples computed */
    int togo;
    int n;
    sample_block_type out;
    register sample_block_values_type out_ptr;

    register sample_block_values_type out_ptr_reg;

    register sample_type * delayptr_reg;
    register sample_type * endptr_reg;
    register sample_block_values_type feedback_ptr_reg;
    register sample_block_values_type s_ptr_reg;
    falloc_sample_block(out, "delaycv_nn_fetch");
    out_ptr = out->samples;
    snd_list->block = out;

    while (cnt < max_sample_block_len) { /* outer loop */
    /* first compute how many samples to generate in inner loop: */
    /* don't overflow the output sample block: */
    togo = max_sample_block_len - cnt;

    /* don't run past the s input sample block: */
    susp_check_term_samples(s, s_ptr, s_cnt);
    togo = min(togo, susp->s_cnt);

    /* don't run past the feedback input sample block: */
    susp_check_samples(feedback, feedback_ptr, feedback_cnt);
    togo = min(togo, susp->feedback_cnt);

    /* don't run past terminate time */
    if (susp->terminate_cnt != UNKNOWN &&
        susp->terminate_cnt <= susp->susp.current + cnt + togo) {
        togo = susp->terminate_cnt - (susp->susp.current + cnt);
        if (togo == 0) break;
    }

    n = togo;
    delayptr_reg = susp->delayptr;
    endptr_reg = susp->endptr;
    feedback_ptr_reg = susp->feedback_ptr;
    s_ptr_reg = susp->s_ptr;
    out_ptr_reg = out_ptr;
    if (n) do { /* the inner sample computation loop */
*out_ptr_reg++ = *delayptr_reg;
         *delayptr_reg = *delayptr_reg * *feedback_ptr_reg++ + *s_ptr_reg++;
         if (++delayptr_reg >= endptr_reg) delayptr_reg = susp->delaybuf;;
    } while (--n); /* inner loop */

    susp->delayptr = delayptr_reg;
    susp->endptr = endptr_reg;
    /* using feedback_ptr_reg is a bad idea on RS/6000: */
    susp->feedback_ptr += togo;
    /* using s_ptr_reg is a bad idea on RS/6000: */
    susp->s_ptr += togo;
    out_ptr += togo;
    susp_took(s_cnt, togo);
    susp_took(feedback_cnt, togo);
    cnt += togo;
    } /* outer loop */

    /* test for termination */
    if (togo == 0 && cnt == 0) {
    snd_list_terminate(snd_list);
    } else {
    snd_list->block_len = cnt;
    susp->susp.current += cnt;
    }
} /* delaycv_nn_fetch */
示例#21
0
void sax_all_nsnnnn_fetch(snd_susp_type a_susp, snd_list_type snd_list)
{
    sax_all_susp_type susp = (sax_all_susp_type) a_susp;
    int cnt = 0; /* how many samples computed */
    int togo;
    int n;
    sample_block_type out;
    register sample_block_values_type out_ptr;

    register sample_block_values_type out_ptr_reg;

    register struct instr * sax_reg;
    register double frequency_reg;
    register float breath_scale_reg;
    register float reed_scale_reg;
    register float noise_scale_reg;
    register float blow_scale_reg;
    register float offset_scale_reg;
    register sample_block_values_type reed_table_offset_ptr_reg;
    register sample_block_values_type blow_pos_ptr_reg;
    register sample_block_values_type noise_env_ptr_reg;
    register sample_block_values_type reed_stiffness_ptr_reg;
    register sample_type freq_env_scale_reg = susp->freq_env->scale;
    register sample_block_values_type freq_env_ptr_reg;
    register sample_block_values_type breath_env_ptr_reg;
    falloc_sample_block(out, "sax_all_nsnnnn_fetch");
    out_ptr = out->samples;
    snd_list->block = out;

    while (cnt < max_sample_block_len) { /* outer loop */
	/* first compute how many samples to generate in inner loop: */
	/* don't overflow the output sample block: */
	togo = max_sample_block_len - cnt;

	/* don't run past the breath_env input sample block: */
	susp_check_term_samples(breath_env, breath_env_ptr, breath_env_cnt);
	togo = min(togo, susp->breath_env_cnt);

	/* don't run past the freq_env input sample block: */
	susp_check_samples(freq_env, freq_env_ptr, freq_env_cnt);
	togo = min(togo, susp->freq_env_cnt);

	/* don't run past the reed_stiffness input sample block: */
	susp_check_samples(reed_stiffness, reed_stiffness_ptr, reed_stiffness_cnt);
	togo = min(togo, susp->reed_stiffness_cnt);

	/* don't run past the noise_env input sample block: */
	susp_check_samples(noise_env, noise_env_ptr, noise_env_cnt);
	togo = min(togo, susp->noise_env_cnt);

	/* don't run past the blow_pos input sample block: */
	susp_check_samples(blow_pos, blow_pos_ptr, blow_pos_cnt);
	togo = min(togo, susp->blow_pos_cnt);

	/* don't run past the reed_table_offset input sample block: */
	susp_check_samples(reed_table_offset, reed_table_offset_ptr, reed_table_offset_cnt);
	togo = min(togo, susp->reed_table_offset_cnt);

	/* don't run past terminate time */
	if (susp->terminate_cnt != UNKNOWN &&
	    susp->terminate_cnt <= susp->susp.current + cnt + togo) {
	    togo = susp->terminate_cnt - (susp->susp.current + cnt);
	    if (togo < 0) togo = 0;  /* avoids rounding errros */
	    if (togo == 0) break;
	}

	n = togo;
	sax_reg = susp->sax;
	frequency_reg = susp->frequency;
	breath_scale_reg = susp->breath_scale;
	reed_scale_reg = susp->reed_scale;
	noise_scale_reg = susp->noise_scale;
	blow_scale_reg = susp->blow_scale;
	offset_scale_reg = susp->offset_scale;
	reed_table_offset_ptr_reg = susp->reed_table_offset_ptr;
	blow_pos_ptr_reg = susp->blow_pos_ptr;
	noise_env_ptr_reg = susp->noise_env_ptr;
	reed_stiffness_ptr_reg = susp->reed_stiffness_ptr;
	freq_env_ptr_reg = susp->freq_env_ptr;
	breath_env_ptr_reg = susp->breath_env_ptr;
	out_ptr_reg = out_ptr;
	if (n) do { /* the inner sample computation loop */
            controlChange(sax_reg, 128, breath_scale_reg * *breath_env_ptr_reg++);
            controlChange(sax_reg, 2, reed_scale_reg * *reed_stiffness_ptr_reg++);
            controlChange(sax_reg, 4, noise_scale_reg * *noise_env_ptr_reg++);
            controlChange(sax_reg, 11, blow_scale_reg * *blow_pos_ptr_reg++);
            controlChange(sax_reg, 26, offset_scale_reg * *reed_table_offset_ptr_reg++);
            setFrequency(sax_reg, frequency_reg + (freq_env_scale_reg * *freq_env_ptr_reg++));
            *out_ptr_reg++ = (sample_type) tick(sax_reg);
	} while (--n); /* inner loop */

	susp->sax = sax_reg;
	/* using reed_table_offset_ptr_reg is a bad idea on RS/6000: */
	susp->reed_table_offset_ptr += togo;
	/* using blow_pos_ptr_reg is a bad idea on RS/6000: */
	susp->blow_pos_ptr += togo;
	/* using noise_env_ptr_reg is a bad idea on RS/6000: */
	susp->noise_env_ptr += togo;
	/* using reed_stiffness_ptr_reg is a bad idea on RS/6000: */
	susp->reed_stiffness_ptr += togo;
	/* using freq_env_ptr_reg is a bad idea on RS/6000: */
	susp->freq_env_ptr += togo;
	/* using breath_env_ptr_reg is a bad idea on RS/6000: */
	susp->breath_env_ptr += togo;
	out_ptr += togo;
	susp_took(breath_env_cnt, togo);
	susp_took(freq_env_cnt, togo);
	susp_took(reed_stiffness_cnt, togo);
	susp_took(noise_env_cnt, togo);
	susp_took(blow_pos_cnt, togo);
	susp_took(reed_table_offset_cnt, togo);
	cnt += togo;
    } /* outer loop */

    /* test for termination */
    if (togo == 0 && cnt == 0) {
	snd_list_terminate(snd_list);
    } else {
	snd_list->block_len = cnt;
	susp->susp.current += cnt;
    }
} /* sax_all_nsnnnn_fetch */
示例#22
0
/*
 * The susp is shared by all channels.  The susp has backpointers
 * to the tail-most snd_list node of each channels, and it is by
 * extending the list at these nodes that sounds are read in.
 * To avoid a circularity, the reference counts on snd_list nodes
 * do not include the backpointers from this susp.  When a snd_list
 * node refcount goes to zero, the multiread susp's free routine
 * is called.  This must scan the backpointers to find the node that
 * has a zero refcount (the free routine is called before the node
 * is deallocated, so this is safe).  The backpointer is then set
 * to NULL.  When all backpointers are NULL, the susp itself is
 * deallocated, because it can only be referenced through the
 * snd_list nodes to which there are backpointers.
 */
void multiread_fetch(snd_susp_type a_susp, snd_list_type snd_list)
{
    read_susp_type susp = (read_susp_type) a_susp;
    int i, j;
    int frames_read = 0; /* total frames read in this call to fetch */
    int n;
    sample_block_type out;
    // char input_buffer[input_buffer_max];
    float input_buffer[input_buffer_samps];
    int file_frame_size;

    /* when we are called, the caller (SND_get_first) will insert a new
     * snd_list node.  We need to do this here for all other channels.
     */
    for (j = 0; j < susp->sf_info.channels; j++) {

/*        nyquist_printf("multiread_fetch: chan[%d] = ", j);
        print_snd_list_type(susp->chan[j]);
        stdputstr("\n");
 */
        if (!susp->chan[j]) {   /* ignore non-existent channels */
/*          nyquist_printf("multiread_fetch: ignore channel %d\n", j);*/
            continue;
        }
        falloc_sample_block(out, "multiread_fetch");
/*      nyquist_printf("multiread: allocated block %x\n", out); */
        /* Since susp->chan[i] exists, we want to append a block of samples.
         * The block, out, has been allocated.  Before we insert the block,
         * we must figure out whether to insert a new snd_list_type node for
         * the block.  Recall that before SND_get_next is called, the last
         * snd_list_type in the list will have a null block pointer, and the
         * snd_list_type's susp field points to the suspension (in this case,
         * susp).  When SND_get_next (in sound.c) is called, it appends a new
         * snd_list_type and points the previous one to internal_zero_block 
         * before calling this fetch routine.  On the other hand, since 
         * SND_get_next is only going to be called on one of the channels, the
         * other channels will not have had a snd_list_type appended.
         * SND_get_next does not tell us directly which channel it wants (it
         * doesn't know), but we can test by looking for a non-null block in the
         * snd_list_type pointed to by our back-pointers in susp->chan[].  If
         * the block is null, the channel was untouched by SND_get_next, and
         * we should append a snd_list_type.  If it is non-null, then it
         * points to internal_zero_block (the block inserted by SND_get_next)
         * and a new snd_list_type has already been appended.
         */
        /* Before proceeding, it may be that garbage collection ran when we
         * allocated out, so check again to see if susp->chan[j] is Null:
         */
        if (!susp->chan[j]) {
            ffree_sample_block(out, "multiread_fetch");
            continue;
        }
        if (!susp->chan[j]->block) {
            snd_list_type snd_list = snd_list_create((snd_susp_type) susp);
            /* Now we have a snd_list to append to the channel, but a very
             * interesting thing can happen here.  snd_list_create, which
             * we just called, MAY have invoked the garbage collector, and
             * the GC MAY have freed all references to this channel, in which
             * case multread_free(susp) will have been called, and susp->chan[j]
             * will now be NULL!
             */
            if (!susp->chan[j]) {
                nyquist_printf("susp %p Channel %d disappeared!\n", susp, j);
                ffree_snd_list(snd_list, "multiread_fetch");
            } else {
                susp->chan[j]->u.next = snd_list;
            }
        }
        /* see the note above: we don't know if susp->chan still exists */
        /* Note: We DO know that susp still exists because even if we lost
         * some channels in a GC, someone is still calling SND_get_next on
         * some channel.  I suppose that there might be some very pathological
         * code that could free a global reference to a sound that is in the
         * midst of being computed, perhaps by doing something bizarre in the
         * closure that snd_seq activates at the logical stop time of its first
         * sound, but I haven't thought that one through.
         */
        if (susp->chan[j]) {
            susp->chan[j]->block = out;
            /* check some assertions */
            if (susp->chan[j]->u.next->u.susp != (snd_susp_type) susp) {
                nyquist_printf("didn't find susp at end of list for chan %d\n", j);
            }
        } else { /* we allocated out, but don't need it anymore due to GC */
            ffree_sample_block(out, "multiread_fetch");
        }
    }

    file_frame_size = susp->sf_info.channels;

    /* now fill sample blocks with frames from the file 
       until eof or end of blocks */
    while (true) {

        /* compute how many frames to read to fill sample blocks */
        long frame_count = max_sample_block_len - frames_read;
        long actual;         /* how many frames actually read */

        /* make sure frames will fit in buffer */
        if (frame_count * file_frame_size > input_buffer_samps) {
            frame_count = input_buffer_samps / file_frame_size;
        }

        actual = sf_readf_float(susp->sndfile, input_buffer, frame_count);
        n = actual;  

        /* don't read too many */
        if (n > (susp->cnt - susp->susp.current)) {
            n = susp->cnt - susp->susp.current;
        }

        /* process one channel at a time, multiple passes through input */
        for (j = 0; j < susp->sf_info.channels; j++) {
            register sample_block_values_type out_ptr;
            /* offset by channel number: */
            float *float_ptr = input_buffer + j;

            /* ignore nonexistent channels */
            if (!susp->chan[j]) continue;

            /* find pointer to sample buffer */
            out_ptr = susp->chan[j]->block->samples + frames_read;

            /* copy samples */
            for (i = 0; i < n; i++) {
                *out_ptr++ = *float_ptr;
                float_ptr += susp->sf_info.channels;
            }
            susp->chan[j]->block_len = frames_read + n;
        }

	/* jlh BECAUSE, at this point, all the code cares about is
	   that n frames have been read and the samples put into their
	   appropriate snd_node buffers. */

        frames_read += n;
        susp->susp.current += n;

        if (frames_read == 0) {
            /* NOTE: this code should probably be removed -- how could we
               ever get here? Since file formats know the sample count, we'll
               always read frames. When we hit the end-of-file, the else
               clause below will run and terminate the sound, so we'll never
               try and read samples that are not there. The only exception is
               an empty sound file with no samples, in which case we could omit
               this if test and execute the else part below.

               This code *might* be good for formats that do not encode a
               sample count and where reading the end of file is the only way
               to detect the end of the data.

               Since it seeems to work, I'm going to leave this in place.
               One tricky point of the algorithm: when we get here, we set up
               susp->chan[j] to point to the right place and then call
               snd_list_terminate(). This deletes the snd_list that chan[j]
               is pointing to, but not before calling multiread_free(), which
               upon detecting that the sound is being freed, sets chan[j] to
               NULL. This works sequentially on each channel and than last
               time, this susp is freed because no channels are active.
             */
            /* we didn't read anything, but can't return length zero, so
             * convert snd_list's to pointer to zero block.  This loop
             * will free the susp via snd_list_unref().
             */
            for (j = 0; j < susp->sf_info.channels; j++) {
                if (susp->chan[j]) {
                    snd_list_type the_snd_list = susp->chan[j];
                    /* this is done so that multiread_free works right: */
                    susp->chan[j] = susp->chan[j]->u.next;
                    /* nyquist_printf("end of file, terminating channel %d\n", j); */
                    /* this fixes up the tail of channel j */
                    snd_list_terminate(the_snd_list);
                }
            }
            return;
        } else if (susp->cnt == susp->susp.current || actual < frame_count) {
            /* we've read the requested number of frames or we
             * reached end of file
             * last iteration will close file and free susp:
             */
            for (j = 0; j < susp->sf_info.channels; j++) {
                snd_list_type the_snd_list = susp->chan[j];
                /* nyquist_printf("reached susp->cnt, terminating chan %d\n", j); */
                if (the_snd_list) {
                    /* assert: */
                    if (the_snd_list->u.next->u.susp != (snd_susp_type) susp) {
                        stdputstr("assertion violation");
                    }
                    /* this is done so that multiread_free works right: */
                    susp->chan[j] = the_snd_list->u.next;
                    snd_list_unref(the_snd_list->u.next);
                    /* terminate by pointing to zero block */
                    the_snd_list->u.next = zero_snd_list;
                }
            }
            return;
        } else if (frames_read >= max_sample_block_len) {
            /* move pointer to next list node */
            for (j = 0; j < susp->sf_info.channels; j++) {
                if (susp->chan[j]) susp->chan[j] = susp->chan[j]->u.next;
            }
            return;
        }
    }
} /* multiread__fetch */
示例#23
0
void fmosc_r_fetch(register fmosc_susp_type susp, snd_list_type snd_list)
{
    int cnt = 0; /* how many samples computed */
    sample_type s_fm_val;
    int togo;
    int n;
    sample_block_type out;
    register sample_block_values_type out_ptr;

    register sample_block_values_type out_ptr_reg;

    register double table_len_reg;
    register double ph_incr_reg;
    register sample_type * table_ptr_reg;
    register double phase_reg;
    falloc_sample_block(out, "fmosc_r_fetch");
    out_ptr = out->samples;
    snd_list->block = out;

    /* make sure sounds are primed with first values */
    if (!susp->started) {
    susp->started = true;
    susp->s_fm_pHaSe = 1.0;
    }

    susp_check_term_log_samples(s_fm, s_fm_ptr, s_fm_cnt);

    while (cnt < max_sample_block_len) { /* outer loop */
    /* first compute how many samples to generate in inner loop: */
    /* don't overflow the output sample block: */
    togo = max_sample_block_len - cnt;

    /* grab next s_fm_x1_sample when phase goes past 1.0; */
    /* use s_fm_n (computed below) to avoid roundoff errors: */
    if (susp->s_fm_n <= 0) {
        susp_check_term_log_samples(s_fm, s_fm_ptr, s_fm_cnt);
        susp->s_fm_x1_sample = susp_fetch_sample(s_fm, s_fm_ptr, s_fm_cnt);
        susp->s_fm_pHaSe -= 1.0;
        /* s_fm_n gets number of samples before phase exceeds 1.0: */
        susp->s_fm_n = (long) ((1.0 - susp->s_fm_pHaSe) *
                    susp->output_per_s_fm);
    }
    togo = min(togo, susp->s_fm_n);
    s_fm_val = susp->s_fm_x1_sample;
    /* don't run past terminate time */
    if (susp->terminate_cnt != UNKNOWN &&
        susp->terminate_cnt <= susp->susp.current + cnt + togo) {
        togo = susp->terminate_cnt - (susp->susp.current + cnt);
        if (togo == 0) break;
    }


    /* don't run past logical stop time */
    if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) {
        int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt);
        /* break if to_stop == 0 (we're at the logical stop)
         * AND cnt > 0 (we're not at the beginning of the
         * output block).
         */
        if (to_stop < togo) {
        if (to_stop == 0) {
            if (cnt) {
            togo = 0;
            break;
            } else /* keep togo as is: since cnt == 0, we
                    * can set the logical stop flag on this
                    * output block
                    */
            susp->logically_stopped = true;
        } else /* limit togo so we can start a new
                * block at the LST
                */
            togo = to_stop;
        }
    }

    n = togo;
    table_len_reg = susp->table_len;
    ph_incr_reg = susp->ph_incr;
    table_ptr_reg = susp->table_ptr;
    phase_reg = susp->phase;
    out_ptr_reg = out_ptr;
    if (n) do { /* the inner sample computation loop */
        long table_index;
        double x1;
table_index = (long) phase_reg;
        x1 = table_ptr_reg[table_index];
        *out_ptr_reg++ = (sample_type) (x1 + (phase_reg - table_index) * 
              (table_ptr_reg[table_index + 1] - x1));
        phase_reg += ph_incr_reg + s_fm_val;
        while (phase_reg > table_len_reg) phase_reg -= table_len_reg;
        /* watch out for negative frequencies! */
        while (phase_reg < 0) phase_reg += table_len_reg;
    } while (--n); /* inner loop */

    susp->phase = phase_reg;
    out_ptr += togo;
    susp->s_fm_pHaSe += togo * susp->s_fm_pHaSe_iNcR;
    susp->s_fm_n -= togo;
    cnt += togo;
    } /* outer loop */

    /* test for termination */
    if (togo == 0 && cnt == 0) {
    snd_list_terminate(snd_list);
    } else {
    snd_list->block_len = cnt;
    susp->susp.current += cnt;
    }
    /* test for logical stop */
    if (susp->logically_stopped) {
    snd_list->logically_stopped = true;
    } else if (susp->susp.log_stop_cnt == susp->susp.current) {
    susp->logically_stopped = true;
    }
} /* fmosc_r_fetch */
示例#24
0
void fmosc_i_fetch(register fmosc_susp_type susp, snd_list_type snd_list)
{
    int cnt = 0; /* how many samples computed */
    int togo;
    int n;
    sample_block_type out;
    register sample_block_values_type out_ptr;

    register sample_block_values_type out_ptr_reg;

    register double table_len_reg;
    register double ph_incr_reg;
    register sample_type * table_ptr_reg;
    register double phase_reg;
    register double s_fm_pHaSe_iNcR_rEg = susp->s_fm_pHaSe_iNcR;
    register double s_fm_pHaSe_ReG;
    register sample_type s_fm_x1_sample_reg;
    falloc_sample_block(out, "fmosc_i_fetch");
    out_ptr = out->samples;
    snd_list->block = out;

    /* make sure sounds are primed with first values */
    if (!susp->started) {
    susp->started = true;
    susp_check_term_log_samples(s_fm, s_fm_ptr, s_fm_cnt);
    susp->s_fm_x1_sample = susp_fetch_sample(s_fm, s_fm_ptr, s_fm_cnt);
    }

    while (cnt < max_sample_block_len) { /* outer loop */
    /* first compute how many samples to generate in inner loop: */
    /* don't overflow the output sample block: */
    togo = max_sample_block_len - cnt;

    /* don't run past terminate time */
    if (susp->terminate_cnt != UNKNOWN &&
        susp->terminate_cnt <= susp->susp.current + cnt + togo) {
        togo = susp->terminate_cnt - (susp->susp.current + cnt);
        if (togo == 0) break;
    }


    /* don't run past logical stop time */
    if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) {
        int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt);
        /* break if to_stop == 0 (we're at the logical stop)
         * AND cnt > 0 (we're not at the beginning of the
         * output block).
         */
        if (to_stop < togo) {
        if (to_stop == 0) {
            if (cnt) {
            togo = 0;
            break;
            } else /* keep togo as is: since cnt == 0, we
                    * can set the logical stop flag on this
                    * output block
                    */
            susp->logically_stopped = true;
        } else /* limit togo so we can start a new
                * block at the LST
                */
            togo = to_stop;
        }
    }

    n = togo;
    table_len_reg = susp->table_len;
    ph_incr_reg = susp->ph_incr;
    table_ptr_reg = susp->table_ptr;
    phase_reg = susp->phase;
    s_fm_pHaSe_ReG = susp->s_fm_pHaSe;
    s_fm_x1_sample_reg = susp->s_fm_x1_sample;
    out_ptr_reg = out_ptr;
    if (n) do { /* the inner sample computation loop */
        long table_index;
        double x1;
        if (s_fm_pHaSe_ReG >= 1.0) {
/* fixup-depends s_fm */
        /* pick up next sample as s_fm_x1_sample: */
        susp->s_fm_ptr++;
        susp_took(s_fm_cnt, 1);
        s_fm_pHaSe_ReG -= 1.0;
        susp_check_term_log_samples_break(s_fm, s_fm_ptr, s_fm_cnt, s_fm_x1_sample_reg);
        s_fm_x1_sample_reg = susp_current_sample(s_fm, s_fm_ptr);
        }
table_index = (long) phase_reg;
        x1 = table_ptr_reg[table_index];
        *out_ptr_reg++ = (sample_type) (x1 + (phase_reg - table_index) * 
              (table_ptr_reg[table_index + 1] - x1));
        phase_reg += ph_incr_reg + s_fm_x1_sample_reg;
        while (phase_reg > table_len_reg) phase_reg -= table_len_reg;
        /* watch out for negative frequencies! */
        while (phase_reg < 0) phase_reg += table_len_reg;
        s_fm_pHaSe_ReG += s_fm_pHaSe_iNcR_rEg;
    } while (--n); /* inner loop */

    togo -= n;
    susp->phase = phase_reg;
    susp->s_fm_pHaSe = s_fm_pHaSe_ReG;
    susp->s_fm_x1_sample = s_fm_x1_sample_reg;
    out_ptr += togo;
    cnt += togo;
    } /* outer loop */

    /* test for termination */
    if (togo == 0 && cnt == 0) {
    snd_list_terminate(snd_list);
    } else {
    snd_list->block_len = cnt;
    susp->susp.current += cnt;
    }
    /* test for logical stop */
    if (susp->logically_stopped) {
    snd_list->logically_stopped = true;
    } else if (susp->susp.log_stop_cnt == susp->susp.current) {
    susp->logically_stopped = true;
    }
} /* fmosc_i_fetch */
示例#25
0
void oneshot_n_fetch(register oneshot_susp_type susp, snd_list_type snd_list)
{
    int cnt = 0; /* how many samples computed */
    int togo;
    int n;
    sample_block_type out;
    register sample_block_values_type out_ptr;

    register sample_block_values_type out_ptr_reg;

    register double lev_reg;
    register long oncount_reg;
    register long cnt_reg;
    register sample_block_values_type input_ptr_reg;
    falloc_sample_block(out, "oneshot_n_fetch");
    out_ptr = out->samples;
    snd_list->block = out;

    while (cnt < max_sample_block_len) { /* outer loop */
	/* first compute how many samples to generate in inner loop: */
	/* don't overflow the output sample block: */
	togo = max_sample_block_len - cnt;

	/* don't run past the input input sample block: */
	susp_check_term_log_samples(input, input_ptr, input_cnt);
	togo = MIN(togo, susp->input_cnt);

	/* don't run past terminate time */
	if (susp->terminate_cnt != UNKNOWN &&
	    susp->terminate_cnt <= susp->susp.current + cnt + togo) {
	    togo = susp->terminate_cnt - (susp->susp.current + cnt);
	    if (togo == 0) break;
	}


	/* don't run past logical stop time */
	if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) {
	    int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt);
	    /* break if to_stop == 0 (we're at the logical stop)
	     * AND cnt > 0 (we're not at the beginning of the
	     * output block).
	     */
	    if (to_stop < togo) {
		if (to_stop == 0) {
		    if (cnt) {
			togo = 0;
			break;
		    } else /* keep togo as is: since cnt == 0, we
		            * can set the logical stop flag on this
		            * output block
		            */
			susp->logically_stopped = true;
		} else /* limit togo so we can start a new
		        * block at the LST
		        */
		    togo = to_stop;
	    }
	}

	n = togo;
	lev_reg = susp->lev;
	oncount_reg = susp->oncount;
	cnt_reg = susp->cnt;
	input_ptr_reg = susp->input_ptr;
	out_ptr_reg = out_ptr;
	if (n) do { /* the inner sample computation loop */
double x = *input_ptr_reg++;
        if (x > lev_reg) cnt_reg = oncount_reg;
        cnt_reg--;
        *out_ptr_reg++ = (cnt_reg >= 0 ? 1.0F : 0.0F);;
	} while (--n); /* inner loop */

	susp->lev = lev_reg;
	susp->oncount = oncount_reg;
	susp->cnt = cnt_reg;
	/* using input_ptr_reg is a bad idea on RS/6000: */
	susp->input_ptr += togo;
	out_ptr += togo;
	susp_took(input_cnt, togo);
	cnt += togo;
    } /* outer loop */

    /* test for termination */
    if (togo == 0 && cnt == 0) {
	snd_list_terminate(snd_list);
    } else {
	snd_list->block_len = cnt;
	susp->susp.current += cnt;
    }
    /* test for logical stop */
    if (susp->logically_stopped) {
	snd_list->logically_stopped = true;
    } else if (susp->susp.log_stop_cnt == susp->susp.current) {
	susp->logically_stopped = true;
    }
} /* oneshot_n_fetch */
示例#26
0
void congen_s_fetch(register congen_susp_type susp, snd_list_type snd_list)
{
    int cnt = 0; /* how many samples computed */
    int togo;
    int n;
    sample_block_type out;
    register sample_block_values_type out_ptr;

    register sample_block_values_type out_ptr_reg;

    register double value_reg;
    register double rise_factor_reg;
    register double fall_factor_reg;
    register sample_type sndin_scale_reg = susp->sndin->scale;
    register sample_block_values_type sndin_ptr_reg;
    falloc_sample_block(out, "congen_s_fetch");
    out_ptr = out->samples;
    snd_list->block = out;

    while (cnt < max_sample_block_len) { /* outer loop */
	/* first compute how many samples to generate in inner loop: */
	/* don't overflow the output sample block: */
	togo = max_sample_block_len - cnt;

	/* don't run past the sndin input sample block: */
	susp_check_term_samples(sndin, sndin_ptr, sndin_cnt);
	togo = MIN(togo, susp->sndin_cnt);

	/* don't run past terminate time */
	if (susp->terminate_cnt != UNKNOWN &&
	    susp->terminate_cnt <= susp->susp.current + cnt + togo) {
	    togo = susp->terminate_cnt - (susp->susp.current + cnt);
	    if (togo == 0) break;
	}

	n = togo;
	value_reg = susp->value;
	rise_factor_reg = susp->rise_factor;
	fall_factor_reg = susp->fall_factor;
	sndin_ptr_reg = susp->sndin_ptr;
	out_ptr_reg = out_ptr;
	if (n) do { /* the inner sample computation loop */
      sample_type current = (sndin_scale_reg * *sndin_ptr_reg++);
    if (current > value_reg) {
        value_reg = current - (current - value_reg) * rise_factor_reg;
    } else {
        value_reg = current - (current - value_reg) * fall_factor_reg;
    }
    *out_ptr_reg++ = (sample_type) value_reg;;
	} while (--n); /* inner loop */

	susp->value = value_reg;
	/* using sndin_ptr_reg is a bad idea on RS/6000: */
	susp->sndin_ptr += togo;
	out_ptr += togo;
	susp_took(sndin_cnt, togo);
	cnt += togo;
    } /* outer loop */

    /* test for termination */
    if (togo == 0 && cnt == 0) {
	snd_list_terminate(snd_list);
    } else {
	snd_list->block_len = cnt;
	susp->susp.current += cnt;
    }
} /* congen_s_fetch */
示例#27
0
void quantize_n_fetch(snd_susp_type a_susp, snd_list_type snd_list)
{
    quantize_susp_type susp = (quantize_susp_type) a_susp;
    int cnt = 0; /* how many samples computed */
    int togo;
    int n;
    sample_block_type out;
    register sample_block_values_type out_ptr;

    register sample_block_values_type out_ptr_reg;

    register double factor_reg;
    register sample_block_values_type s1_ptr_reg;
    falloc_sample_block(out, "quantize_n_fetch");
    out_ptr = out->samples;
    snd_list->block = out;

    while (cnt < max_sample_block_len) { /* outer loop */
	/* first compute how many samples to generate in inner loop: */
	/* don't overflow the output sample block: */
	togo = max_sample_block_len - cnt;

	/* don't run past the s1 input sample block: */
	susp_check_term_log_samples(s1, s1_ptr, s1_cnt);
	togo = min(togo, susp->s1_cnt);

	/* don't run past terminate time */
	if (susp->terminate_cnt != UNKNOWN &&
	    susp->terminate_cnt <= susp->susp.current + cnt + togo) {
	    togo = susp->terminate_cnt - (susp->susp.current + cnt);
	    if (togo < 0) togo = 0;  /* avoids rounding errros */
	    if (togo == 0) break;
	}


	/* don't run past logical stop time */
	if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) {
	    int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt);
	    /* break if to_stop == 0 (we're at the logical stop)
	     * AND cnt > 0 (we're not at the beginning of the
	     * output block).
	     */
	    if (to_stop < 0) to_stop = 0; /* avoids rounding errors */
	    if (to_stop < togo) {
		if (to_stop == 0) {
		    if (cnt) {
			togo = 0;
			break;
		    } else /* keep togo as is: since cnt == 0, we
		            * can set the logical stop flag on this
		            * output block
		            */
			susp->logically_stopped = true;
		} else /* limit togo so we can start a new
		        * block at the LST
		        */
		    togo = to_stop;
	    }
	}

	n = togo;
	factor_reg = susp->factor;
	s1_ptr_reg = susp->s1_ptr;
	out_ptr_reg = out_ptr;
	if (n) do { /* the inner sample computation loop */
            {
		float x = *s1_ptr_reg++ * factor_reg;
		long xx;
		x = (x > 0.0F ? x + 0.5 : x - 0.5);
		xx = (long) x;
		*out_ptr_reg++ = (float) xx;
	    };
	} while (--n); /* inner loop */

	/* using s1_ptr_reg is a bad idea on RS/6000: */
	susp->s1_ptr += togo;
	out_ptr += togo;
	susp_took(s1_cnt, togo);
	cnt += togo;
    } /* outer loop */

    /* test for termination */
    if (togo == 0 && cnt == 0) {
	snd_list_terminate(snd_list);
    } else {
	snd_list->block_len = cnt;
	susp->susp.current += cnt;
    }
    /* test for logical stop */
    if (susp->logically_stopped) {
	snd_list->logically_stopped = true;
    } else if (susp->susp.log_stop_cnt == susp->susp.current) {
	susp->logically_stopped = true;
    }
} /* quantize_n_fetch */
示例#28
0
void tapv_sn_fetch(register tapv_susp_type susp, snd_list_type snd_list)
{
    int cnt = 0; /* how many samples computed */
    int togo;
    int n;
    sample_block_type out;
    register sample_block_values_type out_ptr;

    register sample_block_values_type out_ptr_reg;

    register double offset_reg;
    register double vdscale_reg;
    register double maxdelay_reg;
    register long bufflen_reg;
    register long index_reg;
    register sample_type * buffer_reg;
    register sample_block_values_type vardelay_ptr_reg;
    register sample_type s1_scale_reg = susp->s1->scale;
    register sample_block_values_type s1_ptr_reg;
    falloc_sample_block(out, "tapv_sn_fetch");
    out_ptr = out->samples;
    snd_list->block = out;

    while (cnt < max_sample_block_len) { /* outer loop */
    /* first compute how many samples to generate in inner loop: */
    /* don't overflow the output sample block: */
    togo = max_sample_block_len - cnt;

    /* don't run past the s1 input sample block: */
    susp_check_term_log_samples(s1, s1_ptr, s1_cnt);
    togo = min(togo, susp->s1_cnt);

    /* don't run past the vardelay input sample block: */
    susp_check_term_samples(vardelay, vardelay_ptr, vardelay_cnt);
    togo = min(togo, susp->vardelay_cnt);

    /* don't run past terminate time */
    if (susp->terminate_cnt != UNKNOWN &&
        susp->terminate_cnt <= susp->susp.current + cnt + togo) {
        togo = susp->terminate_cnt - (susp->susp.current + cnt);
        if (togo == 0) break;
    }


    /* don't run past logical stop time */
    if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) {
        int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt);
        /* break if to_stop == 0 (we're at the logical stop)
         * AND cnt > 0 (we're not at the beginning of the
         * output block).
         */
        if (to_stop < togo) {
        if (to_stop == 0) {
            if (cnt) {
            togo = 0;
            break;
            } else /* keep togo as is: since cnt == 0, we
                    * can set the logical stop flag on this
                    * output block
                    */
            susp->logically_stopped = true;
        } else /* limit togo so we can start a new
                * block at the LST
                */
            togo = to_stop;
        }
    }

    n = togo;
    offset_reg = susp->offset;
    vdscale_reg = susp->vdscale;
    maxdelay_reg = susp->maxdelay;
    bufflen_reg = susp->bufflen;
    index_reg = susp->index;
    buffer_reg = susp->buffer;
    vardelay_ptr_reg = susp->vardelay_ptr;
    s1_ptr_reg = susp->s1_ptr;
    out_ptr_reg = out_ptr;
    if (n) do { /* the inner sample computation loop */
            double phase;
        long i;
        phase = *vardelay_ptr_reg++ * vdscale_reg + offset_reg;
        /* now phase should give number of samples of delay */
    if (phase < 0) phase = 0;
    else if (phase > maxdelay_reg) phase = maxdelay_reg;
    phase = (double) index_reg - phase;
    /* now phase is a location in the buffer_reg (before modulo) */

    /* Time out to update the buffer_reg:
     * this is a tricky buffer_reg: buffer_reg[0] == buffer_reg[bufflen_reg]
     * the logical length is bufflen_reg, but the actual length
     * is bufflen_reg + 1 to allow for a repeated sample at the
     * end. This allows for efficient interpolation.
     */ 
        buffer_reg[index_reg++] = (s1_scale_reg * *s1_ptr_reg++);
    if (index_reg > bufflen_reg) {
        buffer_reg[0] = buffer_reg[bufflen_reg];
        index_reg = 1;
    }

    /* back to the phase calculation: 
     * use conditional instead of modulo
     */
    if (phase < 0) phase += bufflen_reg;
    i = (long) phase;    /* put integer part in i */
    phase -= (double) i; /* put fractional part in phase */	     
        *out_ptr_reg++ = (sample_type) (buffer_reg[i] * (1.0 - phase) + 
                buffer_reg[i + 1] * phase);;
    } while (--n); /* inner loop */

    susp->bufflen = bufflen_reg;
    susp->index = index_reg;
    /* using vardelay_ptr_reg is a bad idea on RS/6000: */
    susp->vardelay_ptr += togo;
    /* using s1_ptr_reg is a bad idea on RS/6000: */
    susp->s1_ptr += togo;
    out_ptr += togo;
    susp_took(s1_cnt, togo);
    susp_took(vardelay_cnt, togo);
    cnt += togo;
    } /* outer loop */

    /* test for termination */
    if (togo == 0 && cnt == 0) {
    snd_list_terminate(snd_list);
    } else {
    snd_list->block_len = cnt;
    susp->susp.current += cnt;
    }
    /* test for logical stop */
    if (susp->logically_stopped) {
    snd_list->logically_stopped = true;
    } else if (susp->susp.log_stop_cnt == susp->susp.current) {
    susp->logically_stopped = true;
    }
} /* tapv_sn_fetch */
示例#29
0
void stkchorus_n_fetch(register stkchorus_susp_type susp, snd_list_type snd_list)
{
    int cnt = 0; /* how many samples computed */
    int togo;
    int n;
    sample_block_type out;
    register sample_block_values_type out_ptr;

    register sample_block_values_type out_ptr_reg;

    register struct stkEffect * mych_reg;
    register sample_block_values_type s1_ptr_reg;
    falloc_sample_block(out, "stkchorus_n_fetch");
    out_ptr = out->samples;
    snd_list->block = out;

    while (cnt < max_sample_block_len) { /* outer loop */
	/* first compute how many samples to generate in inner loop: */
	/* don't overflow the output sample block: */
	togo = max_sample_block_len - cnt;

	/* don't run past the s1 input sample block: */
	susp_check_term_log_samples(s1, s1_ptr, s1_cnt);
	togo = min(togo, susp->s1_cnt);

	/* don't run past terminate time */
	if (susp->terminate_cnt != UNKNOWN &&
	    susp->terminate_cnt <= susp->susp.current + cnt + togo) {
	    togo = susp->terminate_cnt - (susp->susp.current + cnt);
	    if (togo == 0) break;
	}


	/* don't run past logical stop time */
	if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) {
	    int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt);
	    /* break if to_stop == 0 (we're at the logical stop)
	     * AND cnt > 0 (we're not at the beginning of the
	     * output block).
	     */
	    if (to_stop < togo) {
		if (to_stop == 0) {
		    if (cnt) {
			togo = 0;
			break;
		    } else /* keep togo as is: since cnt == 0, we
		            * can set the logical stop flag on this
		            * output block
		            */
			susp->logically_stopped = true;
		} else /* limit togo so we can start a new
		        * block at the LST
		        */
		    togo = to_stop;
	    }
	}

	n = togo;
	mych_reg = susp->mych;
	s1_ptr_reg = susp->s1_ptr;
	out_ptr_reg = out_ptr;
	if (n) do { /* the inner sample computation loop */

	*out_ptr_reg++ = (sample_type) (stkEffectTick(mych_reg, *s1_ptr_reg++))
;
	} while (--n); /* inner loop */

	susp->mych = mych_reg;
	/* using s1_ptr_reg is a bad idea on RS/6000: */
	susp->s1_ptr += togo;
	out_ptr += togo;
	susp_took(s1_cnt, togo);
	cnt += togo;
    } /* outer loop */

    /* test for termination */
    if (togo == 0 && cnt == 0) {
	snd_list_terminate(snd_list);
    } else {
	snd_list->block_len = cnt;
	susp->susp.current += cnt;
    }
    /* test for logical stop */
    if (susp->logically_stopped) {
	snd_list->logically_stopped = true;
    } else if (susp->susp.log_stop_cnt == susp->susp.current) {
	susp->logically_stopped = true;
    }
} /* stkchorus_n_fetch */
示例#30
0
void aresonvc_nr_fetch(register aresonvc_susp_type susp, snd_list_type snd_list)
{
    int cnt = 0; /* how many samples computed */
    sample_type hz_val;
    int togo;
    int n;
    sample_block_type out;
    register sample_block_values_type out_ptr;

    register sample_block_values_type out_ptr_reg;

    register double c3co_reg;
    register double c3p1_reg;
    register double c3t4_reg;
    register double omc3_reg;
    register double c2_reg;
    register double c1_reg;
    register int normalization_reg;
    register double y1_reg;
    register double y2_reg;
    register sample_block_values_type s1_ptr_reg;
    falloc_sample_block(out, "aresonvc_nr_fetch");
    out_ptr = out->samples;
    snd_list->block = out;

    /* make sure sounds are primed with first values */
    if (!susp->started) {
    susp->started = true;
    susp->hz_pHaSe = 1.0;
    }

    susp_check_term_samples(hz, hz_ptr, hz_cnt);

    while (cnt < max_sample_block_len) { /* outer loop */
    /* first compute how many samples to generate in inner loop: */
    /* don't overflow the output sample block: */
    togo = max_sample_block_len - cnt;

    /* don't run past the s1 input sample block: */
    susp_check_term_log_samples(s1, s1_ptr, s1_cnt);
    togo = min(togo, susp->s1_cnt);

    /* grab next hz_x1_sample when phase goes past 1.0; */
    /* use hz_n (computed below) to avoid roundoff errors: */
    if (susp->hz_n <= 0) {
        susp_check_term_samples(hz, hz_ptr, hz_cnt);
        susp->hz_x1_sample = susp_fetch_sample(hz, hz_ptr, hz_cnt);
        susp->hz_pHaSe -= 1.0;
        /* hz_n gets number of samples before phase exceeds 1.0: */
        susp->hz_n = (long) ((1.0 - susp->hz_pHaSe) *
                    susp->output_per_hz);
        susp->c2 = susp->c3t4 * cos(susp->hz_x1_sample) / susp->c3p1;
        susp->c1 = (susp->normalization == 0 ? 0.0 :
      (susp->normalization == 1 ? 1.0 - susp->omc3 * sqrt(1.0 - susp->c2 * susp->c2 / susp->c3t4) :
          1.0 - sqrt(susp->c3p1 * susp->c3p1 - susp->c2 * susp->c2) * susp->omc3 / susp->c3p1));
    }
    togo = min(togo, susp->hz_n);
    hz_val = susp->hz_x1_sample;
    /* don't run past terminate time */
    if (susp->terminate_cnt != UNKNOWN &&
        susp->terminate_cnt <= susp->susp.current + cnt + togo) {
        togo = susp->terminate_cnt - (susp->susp.current + cnt);
        if (togo == 0) break;
    }


    /* don't run past logical stop time */
    if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) {
        int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt);
        /* break if to_stop == 0 (we're at the logical stop)
         * AND cnt > 0 (we're not at the beginning of the
         * output block).
         */
        if (to_stop < togo) {
        if (to_stop == 0) {
            if (cnt) {
            togo = 0;
            break;
            } else /* keep togo as is: since cnt == 0, we
                    * can set the logical stop flag on this
                    * output block
                    */
            susp->logically_stopped = true;
        } else /* limit togo so we can start a new
                * block at the LST
                */
            togo = to_stop;
        }
    }

    n = togo;
    c3co_reg = susp->c3co;
    c3p1_reg = susp->c3p1;
    c3t4_reg = susp->c3t4;
    omc3_reg = susp->omc3;
    c2_reg = susp->c2;
    c1_reg = susp->c1;
    normalization_reg = susp->normalization;
    y1_reg = susp->y1;
    y2_reg = susp->y2;
    s1_ptr_reg = susp->s1_ptr;
    out_ptr_reg = out_ptr;
    if (n) do { /* the inner sample computation loop */
            register double y0, current;current = *s1_ptr_reg++;
        y0 = c1_reg * current + c2_reg * y1_reg - c3co_reg * y2_reg;
        *out_ptr_reg++ = (sample_type) y0;
        y2_reg = y1_reg; y1_reg = y0 - current;
    } while (--n); /* inner loop */

    susp->y1 = y1_reg;
    susp->y2 = y2_reg;
    /* using s1_ptr_reg is a bad idea on RS/6000: */
    susp->s1_ptr += togo;
    out_ptr += togo;
    susp_took(s1_cnt, togo);
    susp->hz_pHaSe += togo * susp->hz_pHaSe_iNcR;
    susp->hz_n -= togo;
    cnt += togo;
    } /* outer loop */

    /* test for termination */
    if (togo == 0 && cnt == 0) {
    snd_list_terminate(snd_list);
    } else {
    snd_list->block_len = cnt;
    susp->susp.current += cnt;
    }
    /* test for logical stop */
    if (susp->logically_stopped) {
    snd_list->logically_stopped = true;
    } else if (susp->susp.log_stop_cnt == susp->susp.current) {
    susp->logically_stopped = true;
    }
} /* aresonvc_nr_fetch */