예제 #1
0
int lang_q(){

  printf("\33[0;32m");

/*  U32 cnt = src_one();
  char* ptr = var->src_ptr;
  var->src_ptr += cnt;
  U8* address = (U8*)strtol(ptr,NULL,16);
*/
    U8* address = (U8*)(var->sp_meow->TOS);
    if(!verify_ptr(address+64)){
        src_error("q: illegal address\n");
        return 0;
    }
// printf("SP_MEOW ADDRESS %p\n",address);
  address = lang_ql(address);
  address = lang_ql(address);
  address = lang_ql(address);
  address = lang_ql(address);
  var->sp_meow->TOS = (U32)address;
  printf("\33[0;37m");
  return 1;
}
예제 #2
0
static void
callback_reset_test (int converter)
{   static TEST_CB_DATA test_callback_data ;

    static float output [BUFFER_LEN] ;

    SRC_STATE *src_state ;

    double src_ratio = 1.1 ;
    long read_count, read_total ;
    int k, error ;

    printf ("\tcallback_reset_test (%-28s) ....... ", src_get_name (converter)) ;
    fflush (stdout) ;

    for (k = 0 ; k < ARRAY_LEN (data_one) ; k++)
    {   data_one [k] = 1.0 ;
        data_zero [k] = 0.0 ;
    } ;

    if ((src_state = src_callback_new (test_callback_func, converter, 1, &error, &test_callback_data)) == NULL)
    {   printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
        exit (1) ;
    } ;

    /* Process a bunch of 1.0 valued samples. */
    test_callback_data.channels = 1 ;
    test_callback_data.count = 0 ;
    test_callback_data.total = ARRAY_LEN (data_one) ;
    test_callback_data.data = data_one ;

    read_total = 0 ;
    do
    {   read_count = (ARRAY_LEN (output) - read_total > CB_READ_LEN) ? CB_READ_LEN : ARRAY_LEN (output) - read_total ;
        read_count = src_callback_read (src_state, src_ratio, read_count, output + read_total) ;
        read_total += read_count ;
    }
    while (read_count > 0) ;

    /* Check for errors. */
    if ((error = src_error (src_state)) != 0)
    {   printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
        exit (1) ;
    } ;

    /* Reset the state of the converter.*/
    src_reset (src_state) ;

    /* Process a bunch of 0.0 valued samples. */
    test_callback_data.channels = 1 ;
    test_callback_data.count = 0 ;
    test_callback_data.total = ARRAY_LEN (data_zero) ;
    test_callback_data.data = data_zero ;

    /* Now process some zero data. */
    read_total = 0 ;
    do
    {   read_count = (ARRAY_LEN (output) - read_total > CB_READ_LEN) ? CB_READ_LEN : ARRAY_LEN (output) - read_total ;
        read_count = src_callback_read (src_state, src_ratio, read_count, output + read_total) ;
        read_total += read_count ;
    }
    while (read_count > 0) ;

    /* Check for errors. */
    if ((error = src_error (src_state)) != 0)
    {   printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
        exit (1) ;
    } ;

    /* Finally make sure that the output data is zero ie reset was sucessful. */
    for (k = 0 ; k < BUFFER_LEN / 2 ; k++)
        if (output [k] != 0.0)
        {   printf ("\n\nLine %d : output [%d] should be 0.0, is %f.\n\n", __LINE__, k, output [k]) ;
            save_oct_float ("output.dat", data_one, ARRAY_LEN (data_one), output, ARRAY_LEN (output)) ;
            exit (1) ;
        } ;

    /* Make sure that this function has been exported. */
    src_set_ratio (src_state, 1.0) ;

    /* Delete converter. */
    src_state = src_delete (src_state) ;

    puts ("ok") ;
} /* callback_reset_test */
예제 #3
0
static void
callback_test (int converter, double src_ratio)
{	static TEST_CB_DATA test_callback_data ;
	static float output [BUFFER_LEN] ;

	SRC_STATE	*src_state ;

	long	read_count, read_total ;
	int 	input_len, output_len, error ;

	printf ("\tcallback_test    (SRC ratio = %6.4f) ........... ", src_ratio) ;
	fflush (stdout) ;

	/* Calculate maximun input and output lengths. */
	if (src_ratio >= 1.0)
	{	output_len = BUFFER_LEN ;
		input_len = (int) floor (BUFFER_LEN / src_ratio) ;
		}
	else
	{	input_len = BUFFER_LEN ;
		output_len = (int) floor (BUFFER_LEN * src_ratio) ;
		} ;

	/* Reduce input_len by 10 so output is longer than necessary. */
	input_len -= 10 ;

	if (output_len > BUFFER_LEN)
	{	printf ("\n\nLine %d : output_len > BUFFER_LEN\n\n", __LINE__) ;
		exit (1) ;
		} ;

	test_callback_data.channels = 1 ;
	test_callback_data.count = 0 ;
	test_callback_data.total = input_len ;

	if ((src_state = src_callback_new (test_callback_func, converter, 1, &error, &test_callback_data)) == NULL)
	{	printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
		exit (1) ;
		} ;

	read_total = 0 ;
	do
	{	read_count = (ARRAY_LEN (output) - read_total > CB_READ_LEN) ? CB_READ_LEN : ARRAY_LEN (output) - read_total ;
		read_count = src_callback_read (src_state, src_ratio, read_count, output + read_total) ;
		read_total += read_count ;
		}
	while (read_count > 0) ;

	if ((error = src_error (src_state)) != 0)
	{	printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
		exit (1) ;
		} ;

	src_state = src_delete (src_state) ;

	if (fabs (read_total - src_ratio * input_len) > 2)
	{	printf ("\n\nLine %d : input / output length mismatch.\n\n", __LINE__) ;
		printf ("    input len  : %d\n", input_len) ;
		printf ("    output len : %ld (should be %g +/- 2)\n\n", read_total, floor (0.5 + src_ratio * input_len)) ;
		exit (1) ;
		} ;

	puts ("ok") ;

	return ;
} /* callback_test */
예제 #4
0
static void
callback_test (int converter, int channel_count, double target_snr)
{	TEST_CB_DATA test_callback_data ;
	SRC_STATE	*src_state = NULL ;

	double	freq, snr, src_ratio ;
	int		ch, error, frames, read_total, read_count ;

	printf ("\t%-22s (%d channel%c) ............. ", "callback_test", channel_count, channel_count > 1 ? 's' : ' ') ;
	fflush (stdout) ;

	memset (input_serial, 0, sizeof (input_serial)) ;
	memset (input_interleaved, 0, sizeof (input_interleaved)) ;
	memset (output_interleaved, 0, sizeof (output_interleaved)) ;
	memset (output_serial, 0, sizeof (output_serial)) ;
	memset (&test_callback_data, 0, sizeof (test_callback_data)) ;

	frames = MIN (ARRAY_LEN (input_serial) / channel_count, 1 << 16) ;

	/* Calculate channel_count separate windowed sine waves. */
	for (ch = 0 ; ch < channel_count ; ch++)
	{	freq = (200.0 + 33.333333333 * ch) / 44100.0 ;
		gen_windowed_sines (1, &freq, 1.0, input_serial + ch * frames, frames) ;
		} ;

	/* Interleave the data in preparation for SRC. */
	interleave_data (input_serial, input_interleaved, frames, channel_count) ;

	/* Perform sample rate conversion. */
	src_ratio = 0.95 ;
	test_callback_data.channels = channel_count ;
	test_callback_data.total_frames = frames ;
	test_callback_data.current_frame = 0 ;
	test_callback_data.data = input_interleaved ;

	if ((src_state = src_callback_new (test_callback_func, converter, channel_count, &error, &test_callback_data)) == NULL)
	{	printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
		exit (1) ;
		} ;

	read_total = 0 ;
	while (read_total < frames)
	{	read_count = src_callback_read (src_state, src_ratio, frames - read_total, output_interleaved + read_total * channel_count) ;

		if (read_count <= 0)
			break ;

		read_total += read_count ;
		} ;

	if ((error = src_error (src_state)) != 0)
	{	printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
		exit (1) ;
		} ;

	src_state = src_delete (src_state) ;

	if (fabs (read_total - src_ratio * frames) > 2)
	{	printf ("\n\nLine %d : bad output data length %d should be %d.\n", __LINE__,
					read_total, (int) floor (src_ratio * frames)) ;
		printf ("\tsrc_ratio  : %.4f\n", src_ratio) ;
		printf ("\tinput_len  : %d\n", frames) ;
		printf ("\toutput_len : %d\n\n", read_total) ;
		exit (1) ;
		} ;

	/* De-interleave data so SNR can be calculated for each channel. */
	deinterleave_data (output_interleaved, output_serial, frames, channel_count) ;

	for (ch = 0 ; ch < channel_count ; ch++)
	{	snr = calculate_snr (output_serial + ch * frames, frames, 1) ;
		if (snr < target_snr)
		{	printf ("\n\nLine %d: channel %d snr %f should be %f\n", __LINE__, ch, snr, target_snr) ;
			save_oct_float ("output.dat", input_serial, channel_count * frames, output_serial, channel_count * frames) ;
			exit (1) ;
			} ;
		} ;

	puts ("ok") ;

	return ;
} /* callback_test */