Beispiel #1
0
struct Symbol* conditional_expression(struct ConditionalExpression* node)
{
    struct Symbol* symbol = logical_or_expression(node->logicalOrExpression);
    if (node->type == 0)
        return symbol;
    ADDSTRING("  br i1 ");
    code_gen_symbol('%', symbol);
    struct Symbol* label1 = new_symbol("", 0, 0, 0, 0, 0, 0);
    ADDSTRING(", label ");
    code_gen_symbol('%', label1);
    ADDSTRING(", label ");
    char *ch = g_ptr;
    ADDSTRING("      ");
    ADDSTRING("\n; <label>:");
    code_gen_symbol(0, label1);
    ADDSTRING("\n");
    struct Symbol* symbol1 = load_symbol(expression_func(node->expression));
    ADDSTRING("  br label ");
    char *ch1 = g_ptr;
    ADDSTRING("      ");
    ADDSTRING("\n; <label>:");
    struct Symbol* label2 = new_symbol("", 0, 0, 0, 0, 0, 0);
    code_gen_symbol(0, label2);
    ADDSTRING("\n");
    struct Symbol* symbol2 = load_symbol(expression_func(node->expression));
    ADDSTRING("  br label ");
    struct Symbol* label3 = new_symbol("", 0, 0, 0, 0, 0, 0);
    code_gen_symbol('%', label3);
    ADDSTRING("\n; <label>:");
    code_gen_symbol(0, label3);
    ADDSTRING("\n");
    symbol = new_symbol("", symbol2->storage, symbol2->qualifier, symbol2->specifier, symbol2->stars, 0, symbol2->length);
    code_gen_symbol('%', symbol);
    ADDSTRING(" = phi ");
    code_gen_type_specifier(symbol->specifier,0,symbol->length,symbol->stars);
    ADDSTRING(" [ ");
    code_gen_symbol('%', symbol1);
    ADDSTRING(", ");
    code_gen_symbol('%', label1);
    ADDSTRING(" ], [ ");
    code_gen_symbol('%', symbol2);
    ADDSTRING(", ");
    code_gen_symbol('%', label2);
    ADDSTRING(" ]\n");
    push_buffer(ch);
    code_gen_symbol('%', label2);
    *g_ptr = ' ';
    pop_buffer();
    push_buffer(ch1);
    code_gen_symbol('%', label3);
    *g_ptr = ' ';
    pop_buffer();
    return symbol;
}
Beispiel #2
0
void f_compress (void)
{
   unsigned char* buffer;
   unsigned char* input;
   int size;
   buffer_t* real_buffer;
   uLongf new_size;

   if (sp->type == T_STRING) {
      size = SVALUE_STRLEN(sp);
      input = (unsigned char*)sp->u.string;
   } else if (sp->type == T_BUFFER) {
      size = sp->u.buf->size;
      input = sp->u.buf->item;
   } else {
      pop_n_elems(st_num_arg);
      push_undefined();
      return ;
   }

   new_size = size;
   // Make it a little larger as specified in the docs.
   buffer = (unsigned char*)DXALLOC(size * 101 / 100 + 12, TAG_TEMPORARY, "compress");
   compress(buffer, &new_size, input, size);

   // Shrink it down.
   pop_n_elems(st_num_arg);
   real_buffer = allocate_buffer(new_size);
   write_buffer(real_buffer, 0, (char *)buffer, new_size);
   FREE(buffer);
   push_buffer(real_buffer);
}
Beispiel #3
0
void 
run_adding_Vibrato(LADSPA_Handle Instance,
		   unsigned long SampleCount) {
  
	Vibrato * ptr = (Vibrato *)Instance;

	LADSPA_Data freq = LIMIT(*(ptr->freq),0.0f,PM_FREQ);
	LADSPA_Data depth = 
		LIMIT(LIMIT(*(ptr->depth),0.0f,20.0f) * ptr->sample_rate / 200.0f / M_PI / freq,
		      0, ptr->buflen / 2);
	LADSPA_Data drylevel = db2lin(LIMIT(*(ptr->drylevel),-90.0f,20.0f));
	LADSPA_Data wetlevel = db2lin(LIMIT(*(ptr->wetlevel),-90.0f,20.0f));
	LADSPA_Data * input = ptr->input;
	LADSPA_Data * output = ptr->output;

	unsigned long sample_index;
	unsigned long sample_count = SampleCount;

	LADSPA_Data in = 0.0f;
	LADSPA_Data phase = 0.0f;
	LADSPA_Data fpos = 0.0f;
	LADSPA_Data n = 0.0f;
	LADSPA_Data rem = 0.0f;
	LADSPA_Data s_a, s_b;


	if (freq == 0.0f)
		depth = 0.0f;

	for (sample_index = 0; sample_index < sample_count; sample_index++) {

		in = *(input++);

		phase = COS_TABLE_SIZE * freq * sample_index / ptr->sample_rate + ptr->phase;
		while (phase >= COS_TABLE_SIZE)
		        phase -= COS_TABLE_SIZE;

		push_buffer(in, ptr->ringbuffer, ptr->buflen, &(ptr->pos));

		fpos = depth * (1.0f - cos_table[(unsigned long) phase]);
		n = floorf(fpos);
		rem = fpos - n;

		s_a = read_buffer(ptr->ringbuffer, ptr->buflen, ptr->pos, (unsigned long) n);
		s_b = read_buffer(ptr->ringbuffer, ptr->buflen, ptr->pos, (unsigned long) n + 1);

		*(output++) += ptr->run_adding_gain * wetlevel * ((1 - rem) * s_a + rem * s_b) +
			drylevel * read_buffer(ptr->ringbuffer, ptr->buflen,
					       ptr->pos, ptr->buflen / 2);

	}

	ptr->phase += COS_TABLE_SIZE * freq * sample_index / ptr->sample_rate;
	while (ptr->phase >= COS_TABLE_SIZE)
		ptr->phase -= COS_TABLE_SIZE;

	*(ptr->latency) = ptr->buflen / 2;
}
Beispiel #4
0
    inline void push_cstr (
        formatter_context const & context
      , cstr_type                 cstr
      )
    {
      BPRINTF_ASSERT (cstr);

      auto size = std::strlen (cstr);

      push_buffer (context, cstr, size);
    }
/**
 * gst_vaapi_decoder_put_buffer:
 * @decoder: a #GstVaapiDecoder
 * @buf: a #GstBuffer
 *
 * Queues a #GstBuffer to the HW decoder. The decoder holds a
 * reference to @buf.
 *
 * Caller can notify an End-Of-Stream with @buf set to %NULL. However,
 * if an empty buffer is passed, i.e. a buffer with %NULL data pointer
 * or size equals to zero, then the function ignores this buffer and
 * returns %TRUE.
 *
 * Return value: %TRUE on success
 */
gboolean
gst_vaapi_decoder_put_buffer (GstVaapiDecoder * decoder, GstBuffer * buf)
{
  g_return_val_if_fail (decoder != NULL, FALSE);

  if (buf) {
    if (gst_buffer_get_size (buf) == 0)
      return TRUE;
    buf = gst_buffer_ref (buf);
  }
  return push_buffer (decoder, buf);
}
Beispiel #6
0
void * producer1()
{
	while(1)
	{
		sem_wait(&sem_full);
		pthread_mutex_lock(&mutex);
		push_buffer( (rand() %9) + 1);
		print_buffer();
		printf("P1: \n");
		pthread_mutex_unlock(&mutex);
		sem_post(&sem_empty);		
	}
}
Beispiel #7
0
int mlua_new_buffer(lua_State* L)
{
	assert(L);

	Buffer* buffer;
	if (lua_gettop(L) == 1) {
		lua_Integer size = luaL_checkinteger(L, 1);
		assert_lua_error(L, size > 0, "size should be positive");
		buffer = display_new_buffer(size);
	} else {
		buffer = display_new_auto_buffer(); // let Display choose a size
	}
	assert(buffer);
	push_buffer(L, buffer);
	return 1;
}
bool tx0_send( const void* data, size_t len )
  {
  bool status;
  unsigned char* tail;
  
  /* get current state of tail pointer */
  BSP_CRITICAL_STATEMENT( tail = tx0_tail );

  /* put data into transmit buffer */
  status = push_buffer( &tx0_head, tail, tx0_buff, (unsigned char*)data, len );

  if( status != false ) /* if data was put in the buffer properly */
    uart0_tx_message( tx0_handler ); /* notify the irq that data is ready to send */
  
  return status; /* return status */
  }
Beispiel #9
0
static bool handle_char(void) {
    char c = read_rbr();
    if (c == '$') {
        command_wait = true;
        clear_buffer();

    } else if (buf.checksum_index) {
        buf.checksum_count++;
    } else if (c == '#') {
        buf.checksum_index = buf.length;
    }
    push_buffer(c);
    if (buf.checksum_count == 2 && command_wait) {
        /* Got a command */
        return true;
    }
    return false;
}
bool rx_handler( unsigned char c )
  {
  unsigned char* tail;

  /* get current state of tail pointer */
  BSP_CRITICAL_STATEMENT( tail = rx_tail );
  
  /* put data onto the receive buffer */
  push_buffer( &rx_head, tail, rx_buff, &c, 1 );

#if( defined UART_HARDWARE_HANDSHAKE_IN_SOFTWARE )
  /* if we need to hold off the remote transmitter */
  if( rx_peek( ) >= RX_TX_BUFFER_THROTTLE_LIMIT )
    UART_ASSERT_RTS( UART_RTS_ASSERTED ); /* assert the RTS line */
#endif
  
  return true; /* always accept data received from the uart */
  }
Beispiel #11
0
/* push a sample into an allpass filter and return the sample falling out */
rev_t
allp_run(rev_t insample, ALLP_FILTER * allp) {

	rev_t outsample;
	rev_t pushin;
	pushin = allp->in_gain * allp->fb_gain * insample + allp->fb_gain * allp->last_out;
#ifdef REVERB_CALC_FLOAT
	pushin = DENORM(pushin);
#endif
	outsample = push_buffer(pushin,
				allp->ringbuffer, allp->buflen, allp->buffer_pos);
#ifdef REVERB_CALC_FLOAT
	outsample = DENORM(outsample);
#endif
	allp->last_out = outsample;

	return outsample;
}
Beispiel #12
0
/* push a sample into a comb filter and return the sample falling out */
rev_t
comb_run(rev_t insample, COMB_FILTER * comb) {

	rev_t outsample;
	rev_t pushin;

	pushin = comb->fb_gain * insample + biquad_run(comb->filter, comb->fb_gain * comb->last_out);
#ifdef REVERB_CALC_FLOAT
	pushin = DENORM(pushin);
#endif
	outsample = push_buffer(pushin,
				comb->ringbuffer, comb->buflen, comb->buffer_pos);
#ifdef REVERB_CALC_FLOAT
	outsample = DENORM(outsample);
#endif
	comb->last_out = outsample;

	return outsample;
}
Beispiel #13
0
struct Symbol* logical_or_expression(struct LogicalOrExpression* node)
{
    if (node->type == 0)
        return logical_and_expression(node->logicalAndExpression);
    struct Symbol* symbol1 = load_symbol(logical_or_expression(node->logicalOrExpression));
    struct Symbol* symbol2 = load_symbol(logical_and_expression(node->logicalAndExpression));
    struct Symbol* symbol3 = test_calculable2(&symbol1, &symbol2, 'a');
    if (symbol3)
        return symbol3;
    symbol3 = new_symbol("0", 0, 2, 16, 0, 2, 0);
    symbol3 = equality_symbol(symbol1, symbol3, 2, 1);
    ADDSTRING("  br i1 ");
    code_gen_symbol('%', symbol3);
    struct Symbol* label1 = new_symbol("", 0, 0, 0, 0, 0, 0);
    struct Symbol* label2 = new_symbol("", 0, 0, 0, 0, 0, 0);
    ADDSTRING(", label ");
    char *ch = g_ptr;
    ADDSTRING("      ");
    ADDSTRING(", label ");
    code_gen_symbol('%', label1);
    ADDSTRING("\n; <label>:");
    code_gen_symbol(0, label1);
    ADDSTRING("\n");
    symbol1 = equality_symbol(symbol2, symbol3, 2, 1);
    ADDSTRING("  br label ");
    code_gen_symbol('%', label2);
    ADDSTRING("\n; <label>:");
    code_gen_symbol(0, label2);
    ADDSTRING("\n");
    ADDSTRING("  ");
    symbol2 = new_symbol("", 0, 2, 2, 0, 0, 0);
    code_gen_symbol('%', symbol2);
    ADDSTRING(" = phi i1 [ true, %0 ], [ ");
    code_gen_symbol('%', symbol1);
    ADDSTRING(", ");
    code_gen_symbol('%', label2);
    ADDSTRING(" ]\n");
    push_buffer(ch);
    code_gen_symbol('%', label2);
    *g_ptr = ' ';
    pop_buffer();
    return symbol2;
}
Beispiel #14
0
void 
run_Pinknoise(LADSPA_Handle Instance,
	      unsigned long SampleCount) {
  
	Pinknoise * ptr = (Pinknoise *)Instance;

	LADSPA_Data * input = ptr->input;
	LADSPA_Data * output = ptr->output;
	LADSPA_Data hurst = LIMIT(*(ptr->hurst), 0.0f, 1.0f);
	LADSPA_Data signal = db2lin(LIMIT(*(ptr->signal), -90.0f, 20.0f));
	LADSPA_Data noise = db2lin(LIMIT(*(ptr->noise), -90.0f, 20.0f));
	unsigned long sample_index;
	
  	for (sample_index = 0; sample_index < SampleCount; sample_index++) {

		if (!ptr->pos)
			fractal(ptr->ring, NOISE_LEN, hurst);

		*(output++) = signal * *(input++) +
			noise * push_buffer(0.0f, ptr->ring, ptr->buflen, &(ptr->pos));
	}
}
Beispiel #15
0
void 
run_adding_Reflector(LADSPA_Handle Instance,
		     unsigned long SampleCount) {
  
	Reflector * ptr = (Reflector *)Instance;
	LADSPA_Data * input = ptr->input;
	LADSPA_Data * output = ptr->output;
	LADSPA_Data drylevel = db2lin(LIMIT(*(ptr->drylevel),-90.0f,20.0f));
	LADSPA_Data wetlevel = 0.333333f * db2lin(LIMIT(*(ptr->wetlevel),-90.0f,20.0f));
	LADSPA_Data fragment = LIMIT(*(ptr->fragment),(float)MIN_FRAGMENT_LEN,(float)MAX_FRAGMENT_LEN);

	unsigned long sample_index;
	unsigned long sample_count = SampleCount;

	LADSPA_Data in = 0.0f;
	LADSPA_Data in1 = 0.0f;
	LADSPA_Data in2 = 0.0f;
	LADSPA_Data out_0 = 0.0f;
	LADSPA_Data out_1 = 0.0f;
	LADSPA_Data out_2 = 0.0f;

	unsigned long fragment_pos1 = 0;
	unsigned long fragment_pos2 = 0;

	unsigned long arg_0 = 0;
	LADSPA_Data am_0 = 0.0f;
	unsigned long arg_1 = 0;
	LADSPA_Data am_1 = 0.0f;
	unsigned long arg_2 = 0;
	LADSPA_Data am_2 = 0.0f;

	ptr->buflen0 = 2 * fragment * ptr->sample_rate / 1000.0f;
	ptr->buflen1 = ptr->buflen0;
	ptr->buflen2 = ptr->buflen0;
	ptr->delay_buflen1 = ptr->buflen0 / 3;
	ptr->delay_buflen2 = 2 * ptr->buflen0 / 3;

	for (sample_index = 0; sample_index < sample_count; sample_index++) {

		in = *(input++);
		in1 = push_buffer(in, ptr->delay1, ptr->delay_buflen1, &(ptr->delay_pos1));
		in2 = push_buffer(in, ptr->delay2, ptr->delay_buflen2, &(ptr->delay_pos2));

		push_buffer(in2, ptr->ring0, ptr->buflen0, &(ptr->pos0));
		push_buffer(in1, ptr->ring1, ptr->buflen1, &(ptr->pos1));
		push_buffer(in, ptr->ring2, ptr->buflen2, &(ptr->pos2));

		fragment_pos1 = (ptr->fragment_pos + ptr->buflen0 / 3) % ptr->buflen0;
		fragment_pos2 = (ptr->fragment_pos + 2 * ptr->buflen1 / 3) % ptr->buflen1;

		out_0 = read_buffer(ptr->ring0, ptr->buflen0, ptr->pos0,
				    ptr->buflen0 - ptr->fragment_pos - 1);
		out_1 = read_buffer(ptr->ring1, ptr->buflen1, ptr->pos1,
				    ptr->buflen1 - fragment_pos1 - 1);
		out_2 = read_buffer(ptr->ring2, ptr->buflen2, ptr->pos2,
				    ptr->buflen2 - fragment_pos2 - 1);

		ptr->fragment_pos += 2;
		if (ptr->fragment_pos >= ptr->buflen0)
			ptr->fragment_pos = 0;

		arg_0 = (float)ptr->fragment_pos / (float)ptr->buflen0 * COS_TABLE_SIZE;
		am_0 = 1.0f - cos_table[arg_0];
		arg_1 = (float)fragment_pos1 / (float)ptr->buflen1 * COS_TABLE_SIZE;
		am_1 = 1.0f - cos_table[arg_1];
		arg_2 = (float)fragment_pos2 / (float)ptr->buflen2 * COS_TABLE_SIZE;
		am_2 = 1.0f - cos_table[arg_2];

		*(output++) += ptr->run_adding_gain *
			(drylevel * in + wetlevel * (am_0 * out_0 + am_1 * out_1 + am_2 * out_2));
	}
}
Beispiel #16
0
void 	bf_do_cmd(int size, char* cmd)
{
	int	stack = 0;
	int	pc = 0;

	if( 0 == tape_inited )
		init_tape();

	if( 0 == cmd )
		return;

	while( 1 ){
		if( pc >= size )
			break;

		switch( (char)cmd[pc] ){
			case '+':
				tape[get_tape_pos()]++;
				break;
			case '-':
				tape[get_tape_pos()]--;
				break;
			case '.':
				// save in buffer
				push_buffer( tape[get_tape_pos()] );
				break;
			case ',':
				tape[get_tape_pos()] = cmd[pc];
				break;
			case '>':
				inc_tape_pos();
				break;
			case '<':
				dec_tape_pos();
				break;
			case '[':
				if( 0 == tape[get_tape_pos()] ){
					pc++;
					while( 1 ){
						if( pc >= size ) break;
						if( stack <= 0 && cmd[pc] == ']' ) break;
						if( cmd[pc] == '[' ) stack++;
						if( cmd[pc] == ']' ) stack--;
						pc++;
					}
				}
				break;
			case ']':
				pc--;
				while( 1 ){
					if( pc < 0 ) break;
					if( stack <= 0 && cmd[pc] == '[' ) break;
					if( cmd[pc] == ']' ) stack++;
					if( cmd[pc] == '[' ) stack--;
					pc--;
				}
				pc--;
				break;
			case '*':
				// invoke syscall
				break;
			default:
				break;
		}
		pc++;
	}

	return;
}
Beispiel #17
0
void f_uncompress (void)
{
   z_stream* compressed;
   unsigned char compress_buf[COMPRESS_BUF_SIZE];
   unsigned char* output_data = NULL;
   int len;
   int pos;
   buffer_t* buffer;
   int ret;

   if (sp->type == T_BUFFER) {
      buffer = sp->u.buf;
   } else {
      pop_n_elems(st_num_arg);
      push_undefined();
      return ;
   }

   compressed = (z_stream *)
            DXALLOC(sizeof(z_stream), TAG_INTERACTIVE,
                    "start_compression");
   compressed->next_in = buffer->item;
   compressed->avail_in = buffer->size;
   compressed->next_out = compress_buf;
   compressed->avail_out = COMPRESS_BUF_SIZE;
   compressed->zalloc = zlib_alloc;
   compressed->zfree = zlib_free;
   compressed->opaque = NULL;

   if (inflateInit(compressed) != Z_OK) {
      FREE(compressed);
      pop_n_elems(st_num_arg);
      push_undefined();
      return ;
   }

   len = 0;
   output_data = NULL;
   do {
      ret = inflate(compressed, 0);
      if (ret == Z_OK) {
         pos = len;
         len += COMPRESS_BUF_SIZE - compressed->avail_out;
         if (!output_data) {
            output_data = (unsigned char*)DXALLOC(len, TAG_TEMPORARY, "uncompress");
         } else {
            output_data = REALLOC(output_data, len);
         }
         memcpy(output_data + pos, compress_buf, len - pos);
         compressed->next_out = compress_buf;
         compressed->avail_out = COMPRESS_BUF_SIZE;
      }
   } while (ret == Z_OK);

   inflateEnd(compressed);

   pop_n_elems(st_num_arg);

   if (ret == Z_STREAM_END) {
      buffer = allocate_buffer(len);
      memcpy(buffer->item, output_data, len);
      FREE(output_data);
      push_buffer(buffer);
   } else {
      push_undefined();
   }
}
Beispiel #18
0
void 
run_adding_Limiter(LADSPA_Handle Instance,
		   unsigned long SampleCount) {
  
	Limiter * ptr = (Limiter *)Instance;

	LADSPA_Data * input = ptr->input;
	LADSPA_Data * output = ptr->output;
	LADSPA_Data limit_vol = db2lin(LIMIT(*(ptr->limit_vol),-30.0f,20.0f));
	LADSPA_Data out_vol = db2lin(LIMIT(*(ptr->out_vol),-30.0f,20.0f));
	unsigned long sample_index;
	unsigned long sample_count = SampleCount;
	unsigned long index_offs = 0;
	unsigned long i;
	LADSPA_Data max_value = 0;
	LADSPA_Data section_gain = 0;
	unsigned long run_length;
	unsigned long total_length = 0;


	while (total_length < sample_count) {

		run_length = ptr->buflen;
		if (total_length + run_length > sample_count)
			run_length = sample_count - total_length;
		
		while (ptr->ready_num < run_length) {
			if (read_buffer(ptr->ringbuffer, ptr->buflen,
					ptr->pos, ptr->ready_num) >= 0.0f) {
				index_offs = 0;
				while ((read_buffer(ptr->ringbuffer, ptr->buflen, ptr->pos,
						    ptr->ready_num + index_offs) >= 0.0f) &&
				       (ptr->ready_num + index_offs < run_length)) {
					index_offs++;
				}
			} else {
				index_offs = 0;
				while ((read_buffer(ptr->ringbuffer, ptr->buflen, ptr->pos,
						    ptr->ready_num + index_offs) <= 0.0f) &&
				       (ptr->ready_num + index_offs < run_length)) {
					index_offs++;
				}
			}
			
			/* search for max value in scanned halfcycle */
			max_value = 0;
			for (i = ptr->ready_num; i < ptr->ready_num + index_offs; i++) {
				if (fabs(read_buffer(ptr->ringbuffer, ptr->buflen,
						     ptr->pos, i)) > max_value)
					max_value = fabs(read_buffer(ptr->ringbuffer,
								     ptr->buflen, ptr->pos, i));
			}
			section_gain = limit_vol / max_value;
			if (max_value > limit_vol)
				for (i = ptr->ready_num; i < ptr->ready_num + index_offs; i++) {
					write_buffer(read_buffer(ptr->ringbuffer, ptr->buflen,
								 ptr->pos, i) * section_gain,
						     ptr->ringbuffer, ptr->buflen, ptr->pos, i);
				}
			ptr->ready_num += index_offs;			
		}
		
		/* push run_length values out of ringbuffer, feed with input */
		for (sample_index = 0; sample_index < run_length; sample_index++) {
			*(output++) += ptr->run_adding_gain * out_vol * 
				push_buffer(*(input++), ptr->ringbuffer,
					    ptr->buflen, &(ptr->pos));
		}
		ptr->ready_num -= run_length;
		total_length += run_length;
	}	
	*(ptr->latency) = ptr->buflen;
}
Beispiel #19
0
void
run_Echo(LV2_Handle Instance,
	 uint32_t SampleCount) {

	Echo * ptr;
	unsigned long sample_index;

	float delaytime_L;
	float delaytime_R;
	float feedback_L;
	float feedback_R;
	float strength_L;
	float strength_R;
	float drylevel;
	float mode;
	float haas;
	float rev_outch;

	float * input_L;
	float * output_L;
	float * input_R;
	float * output_R;

	unsigned long sample_rate;
	unsigned long buflen_L;
	unsigned long buflen_R;

	float out_L = 0;
	float out_R = 0;
	float in_L = 0;
	float in_R = 0;

	ptr = (Echo *)Instance;

	delaytime_L = LIMIT(*(ptr->delaytime_L),0.0f,2000.0f);
	delaytime_R = LIMIT(*(ptr->delaytime_R),0.0f,2000.0f);
	feedback_L = LIMIT(*(ptr->feedback_L) / 100.0, 0.0f, 100.0f);
	feedback_R = LIMIT(*(ptr->feedback_R) / 100.0, 0.0f, 100.0f);

	ptr->smoothstrength_L = (*(ptr->strength_L)+ptr->smoothstrength_L)*0.5; //smoothing
	strength_L = db2lin(LIMIT(ptr->smoothstrength_L,-70.0f,10.0f)); //convert to db and influence the actual audiobuffer

	ptr->smoothstrength_R = (*(ptr->strength_R)+ptr->smoothstrength_R)*0.5; //smoothing
	strength_R = db2lin(LIMIT(ptr->smoothstrength_R,-70.0f,10.0f)); //convert to db and influence the actual audiobuffer

	ptr->smoothdry = (*(ptr->drylevel)+ptr->smoothdry)*0.5; //smoothing
	drylevel = db2lin(LIMIT(ptr->smoothdry,-70.0f,10.0f));//convert to db and influence the actual audiobuffer

	mode = LIMIT(*(ptr->mode),-2.0f,2.0f);
	haas = LIMIT(*(ptr->haas),-2.0f,2.0f);
	rev_outch = LIMIT(*(ptr->rev_outch),-2.0f,2.0f);

      	input_L = ptr->input_L;
	output_L = ptr->output_L;
      	input_R = ptr->input_R;
	output_R = ptr->output_R;

	sample_rate = ptr->sample_rate;
	buflen_L = delaytime_L * sample_rate / 1000;
	buflen_R = delaytime_R * sample_rate / 1000;


	for (sample_index = 0; sample_index < SampleCount; sample_index++) {

		in_L = *(input_L++);
		in_R = *(input_R++);

		out_L = in_L * drylevel + ptr->mpx_out_L * strength_L;
		out_R = in_R * drylevel + ptr->mpx_out_R * strength_R;

		if (haas > 0.0f)
			in_R = 0.0f;

		if (mode <= 0.0f) {
			ptr->mpx_out_L =
				M(push_buffer(in_L + ptr->mpx_out_L * feedback_L,
					      ptr->ringbuffer_L, buflen_L, ptr->buffer_pos_L));
			ptr->mpx_out_R =
				M(push_buffer(in_R + ptr->mpx_out_R * feedback_R,
					      ptr->ringbuffer_R, buflen_R, ptr->buffer_pos_R));
		} else {
			ptr->mpx_out_R =
				M(push_buffer(in_L + ptr->mpx_out_L * feedback_L,
					      ptr->ringbuffer_L, buflen_L, ptr->buffer_pos_L));
			ptr->mpx_out_L =
				M(push_buffer(in_R + ptr->mpx_out_R * feedback_R,
					      ptr->ringbuffer_R, buflen_R, ptr->buffer_pos_R));
		}

		if (rev_outch <= 0.0f) {
			*(output_L++) = out_L;
			*(output_R++) = out_R;
		} else {
			*(output_L++) = out_R;
			*(output_R++) = out_L;
		}
	}
}
void 
run_adding_ChorusFlanger(LADSPA_Handle Instance,
                         unsigned long SampleCount) {
  
	ChorusFlanger * ptr = (ChorusFlanger *)Instance;

	LADSPA_Data freq = LIMIT(*(ptr->freq), 0.0f, MAX_FREQ);
	LADSPA_Data phase = LIMIT(*(ptr->phase), 0.0f, 180.0f) / 180.0f;
	LADSPA_Data depth = 100.0f * ptr->sample_rate / 44100.0f
		* LIMIT(*(ptr->depth),0.0f,100.0f) / 100.0f;
	LADSPA_Data delay = LIMIT(*(ptr->delay),0.0f,100.0f);
	LADSPA_Data contour = LIMIT(*(ptr->contour), 20.0f, 20000.0f);
	LADSPA_Data drylevel = db2lin(LIMIT(*(ptr->drylevel),-90.0f,20.0f));
	LADSPA_Data wetlevel = db2lin(LIMIT(*(ptr->wetlevel),-90.0f,20.0f));
	LADSPA_Data * input_L = ptr->input_L;
	LADSPA_Data * input_R = ptr->input_R;
	LADSPA_Data * output_L = ptr->output_L;
	LADSPA_Data * output_R = ptr->output_R;

	unsigned long sample_index;
	unsigned long sample_count = SampleCount;

	LADSPA_Data in_L = 0.0f;
	LADSPA_Data in_R = 0.0f;
	LADSPA_Data d_L = 0.0f;
	LADSPA_Data d_R = 0.0f;
	LADSPA_Data f_L = 0.0f;
	LADSPA_Data f_R = 0.0f;
	LADSPA_Data out_L = 0.0f;
	LADSPA_Data out_R = 0.0f;

	float phase_L = 0.0f;
	float phase_R = 0.0f;
	float fpos_L = 0.0f;
	float fpos_R = 0.0f;
	float n_L = 0.0f;
	float n_R = 0.0f;
	float rem_L = 0.0f;
	float rem_R = 0.0f;
	float s_a_L, s_a_R, s_b_L, s_b_R;

	float d_pos = 0.0f;

	if (delay < 1.0f)
		delay = 1.0f;
	delay = 100.0f - delay;

	hp_set_params(&ptr->highpass_L, contour, HP_BW, ptr->sample_rate);
	hp_set_params(&ptr->highpass_R, contour, HP_BW, ptr->sample_rate);

	for (sample_index = 0; sample_index < sample_count; sample_index++) {

		in_L = *(input_L++);
		in_R = *(input_R++);

		push_buffer(in_L, ptr->ring_L, ptr->buflen_L, &(ptr->pos_L));
		push_buffer(in_R, ptr->ring_R, ptr->buflen_R, &(ptr->pos_R));
		
		ptr->cm_phase += freq / ptr->sample_rate * COS_TABLE_SIZE;
		
		while (ptr->cm_phase >= COS_TABLE_SIZE)
			ptr->cm_phase -= COS_TABLE_SIZE;
		
		ptr->dm_phase = phase * COS_TABLE_SIZE / 2.0f;
		
		phase_L = ptr->cm_phase;
		phase_R = ptr->cm_phase + ptr->dm_phase;
		while (phase_R >= COS_TABLE_SIZE)
			phase_R -= COS_TABLE_SIZE;
		
		d_pos = delay * ptr->sample_rate / 1000.0f;
		fpos_L = d_pos + depth * (0.5f + 0.5f * cos_table[(unsigned long)phase_L]);
		fpos_R = d_pos + depth * (0.5f + 0.5f * cos_table[(unsigned long)phase_R]);
		
		n_L = floorf(fpos_L);
		n_R = floorf(fpos_R);
		rem_L = fpos_L - n_L;
		rem_R = fpos_R - n_R;
		
		s_a_L = read_buffer(ptr->ring_L, ptr->buflen_L,
				    ptr->pos_L, (unsigned long) n_L);
		s_b_L = read_buffer(ptr->ring_L, ptr->buflen_L,
				    ptr->pos_L, (unsigned long) n_L + 1);
		
		s_a_R = read_buffer(ptr->ring_R, ptr->buflen_R,
				    ptr->pos_R, (unsigned long) n_R);
		s_b_R = read_buffer(ptr->ring_R, ptr->buflen_R,
				    ptr->pos_R, (unsigned long) n_R + 1);
		
		d_L = ((1 - rem_L) * s_a_L + rem_L * s_b_L);
		d_R = ((1 - rem_R) * s_a_R + rem_R * s_b_R);

		f_L = biquad_run(&ptr->highpass_L, d_L);
		f_R = biquad_run(&ptr->highpass_R, d_R);

		out_L = drylevel * in_L + wetlevel * f_L;
		out_R = drylevel * in_R + wetlevel * f_R;

		*(output_L++) += ptr->run_adding_gain * out_L;
		*(output_R++) += ptr->run_adding_gain * out_R;
	}
}
Beispiel #21
0
float *CLimiter::GetNextA(const int ProcIndex) {
    float* InSignal=FetchA(jnIn);
    if (!InSignal) return NULL;
    unsigned int sample_index;
    unsigned int sample_count = m_BufferSize;
    unsigned int index_offs = 0;
    unsigned int i;
    float max_value = 0;
    float section_gain = 0;
    unsigned int run_length;
    unsigned int total_length = 0;
    float* output=AudioBuffers[ProcIndex]->Buffer;
    float* input=InSignal;

    while (total_length < sample_count)
    {
        run_length = buflen;
        if (total_length + run_length > sample_count)
            run_length = sample_count - total_length;

        while (ready_num < run_length)
        {
            //look for zero-crossings and detect a half cycle
            if (read_buffer(ringbuffer, buflen,pos, ready_num) >= 0)
            {
                index_offs = 0;
                while ((read_buffer(ringbuffer, buflen, pos, ready_num + index_offs) >= 0) &&
                        (ready_num + index_offs < run_length))
                {
                    index_offs++;
                }
            }
            else
            {
                index_offs = 0;
                while ((read_buffer(ringbuffer, buflen, pos, ready_num + index_offs) <= 0) &&
                        (ready_num + index_offs < run_length))
                {
                    index_offs++;
                }
            }

            /* search for max value in scanned halfcycle */
            max_value = 0;
            for (i = ready_num; i < ready_num + index_offs; i++)
            {
                if (fabs(read_buffer(ringbuffer, buflen, pos, i)) > max_value)
                {
                    max_value = fabs(read_buffer(ringbuffer, buflen, pos, i));
                }
            }
            if (max_value>0)
            {
                section_gain = limit_vol / max_value;
            }
            else
            {
                section_gain = 1.0;
            }
            if (max_value > limit_vol)
            {
                for (i = ready_num; i < ready_num + index_offs; i++)
                {
                    write_buffer(read_buffer(ringbuffer, buflen, pos, i) * section_gain, ringbuffer, buflen, pos, i);
                }
            }
            ready_num += index_offs;
        }

        /* push run_length values out of ringbuffer, feed with input */
        for (sample_index = 0; sample_index < run_length; sample_index++)
        {
            *(output++) = out_vol * push_buffer(*(input++), ringbuffer, buflen, &(pos));
        }
        ready_num -= run_length;
        total_length += run_length;
    }
    //*(latency) = buflen;
    return AudioBuffers[ProcIndex]->Buffer;
}
Beispiel #22
0
void
run_ChorusFlanger(LV2_Handle Instance,
		  uint32_t SampleCount) {

	ChorusFlanger * ptr = (ChorusFlanger *)Instance;

	float freq = LIMIT(*(ptr->freq), 0.0f, MAX_FREQ);

	float calcphase = (*(ptr->phase)+ptr->smoothphase)*0.5;
	ptr->smoothphase=calcphase;
	float phase = LIMIT(calcphase, 0.0f, 180.0f) / 180.0f;

	float calcdepth = (*(ptr->depth)+ptr->smoothdepth)*0.5;
	ptr->smoothdepth=calcdepth;
	float depth = 100.0f * ptr->sample_rate / 44100.0f
		* LIMIT(calcdepth,0.0f,100.0f) / 100.0f;

	float calcdelay = (*(ptr->delay)+ptr->smoothdelay)*0.5;
	ptr->smoothdelay=calcdelay;
	float delay = LIMIT(calcdelay,0.0f,100.0f);
	float contour = LIMIT(*(ptr->contour), 20.0f, 20000.0f);

	float calcdry = (*(ptr->drylevel)+ptr->smoothdry)*0.5;
	ptr->smoothdry=calcdry;
	float drylevel = db2lin(LIMIT(calcdry,-90.0f,20.0f));

	float calcwet = (*(ptr->wetlevel)+ptr->smoothwet)*0.5;
	ptr->smoothwet=calcwet;
	float wetlevel = db2lin(LIMIT(calcwet,-90.0f,20.0f));
	float * input_L = ptr->input_L;
	float * input_R = ptr->input_R;
	float * output_L = ptr->output_L;
	float * output_R = ptr->output_R;

	unsigned long sample_index;
	unsigned long sample_count = SampleCount;

	float in_L = 0.0f;
	float in_R = 0.0f;
	float d_L = 0.0f;
	float d_R = 0.0f;
	float f_L = 0.0f;
	float f_R = 0.0f;
	float out_L = 0.0f;
	float out_R = 0.0f;

	float phase_L = 0.0f;
	float phase_R = 0.0f;
	float fpos_L = 0.0f;
	float fpos_R = 0.0f;
	float n_L = 0.0f;
	float n_R = 0.0f;
	float rem_L = 0.0f;
	float rem_R = 0.0f;
	float s_a_L, s_a_R, s_b_L, s_b_R;

	float d_pos = 0.0f;

	if (delay < 1.0f)
		delay = 1.0f;
	delay = 100.0f - delay;

	hp_set_params(&ptr->highpass_L, contour, HP_BW, ptr->sample_rate);
	hp_set_params(&ptr->highpass_R, contour, HP_BW, ptr->sample_rate);

	for (sample_index = 0; sample_index < sample_count; sample_index++) {

		in_L = *(input_L++);
		in_R = *(input_R++);

		push_buffer(in_L, ptr->ring_L, ptr->buflen_L, &(ptr->pos_L));
		push_buffer(in_R, ptr->ring_R, ptr->buflen_R, &(ptr->pos_R));

		ptr->cm_phase += freq / ptr->sample_rate * COS_TABLE_SIZE;

		while (ptr->cm_phase >= COS_TABLE_SIZE)
			ptr->cm_phase -= COS_TABLE_SIZE;

		ptr->dm_phase = phase * COS_TABLE_SIZE / 2.0f;

		phase_L = ptr->cm_phase;
		phase_R = ptr->cm_phase + ptr->dm_phase;
		while (phase_R >= COS_TABLE_SIZE)
			phase_R -= COS_TABLE_SIZE;

		d_pos = delay * ptr->sample_rate / 1000.0f;
		fpos_L = d_pos + depth * (0.5f + 0.5f * cos_table[(unsigned long)phase_L]);
		fpos_R = d_pos + depth * (0.5f + 0.5f * cos_table[(unsigned long)phase_R]);

		n_L = floorf(fpos_L);
		n_R = floorf(fpos_R);
		rem_L = fpos_L - n_L;
		rem_R = fpos_R - n_R;

		s_a_L = read_buffer(ptr->ring_L, ptr->buflen_L,
				    ptr->pos_L, (unsigned long) n_L);
		s_b_L = read_buffer(ptr->ring_L, ptr->buflen_L,
				    ptr->pos_L, (unsigned long) n_L + 1);

		s_a_R = read_buffer(ptr->ring_R, ptr->buflen_R,
				    ptr->pos_R, (unsigned long) n_R);
		s_b_R = read_buffer(ptr->ring_R, ptr->buflen_R,
				    ptr->pos_R, (unsigned long) n_R + 1);

		d_L = ((1 - rem_L) * s_a_L + rem_L * s_b_L);
		d_R = ((1 - rem_R) * s_a_R + rem_R * s_b_R);

		f_L = biquad_run(&ptr->highpass_L, d_L);
		f_R = biquad_run(&ptr->highpass_R, d_R);

		out_L = drylevel * in_L + wetlevel * f_L;
		out_R = drylevel * in_R + wetlevel * f_R;

		*(output_L++) = out_L;
		*(output_R++) = out_R;
	}
}
Beispiel #23
0
void
run_Reflector(LV2_Handle Instance,
          uint32_t SampleCount) {


    Reflector * ptr = (Reflector *)Instance;
    float * input = ptr->input;
    float * output = ptr->output;
    float drylevel = db2lin(LIMIT(*(ptr->drylevel),-90.0f,20.0f));
    float wetlevel = 0.333333f * db2lin(LIMIT(*(ptr->wetlevel),-90.0f,20.0f));
    float fragment = LIMIT(*(ptr->fragment),(float)MIN_FRAGMENT_LEN,(float)MAX_FRAGMENT_LEN);

    unsigned long sample_index;
    unsigned long sample_count = SampleCount;

    float in = 0.0f;
    float in1 = 0.0f;
    float in2 = 0.0f;
    float out_0 = 0.0f;
    float out_1 = 0.0f;
    float out_2 = 0.0f;

    unsigned long fragment_pos1 = 0;
    unsigned long fragment_pos2 = 0;

    unsigned long arg_0 = 0;
    float am_0 = 0.0f;
    unsigned long arg_1 = 0;
    float am_1 = 0.0f;
    unsigned long arg_2 = 0;
    float am_2 = 0.0f;

    ptr->buflen0 = 2 * fragment * ptr->sample_rate / 1000.0f;
    ptr->buflen1 = ptr->buflen0;
    ptr->buflen2 = ptr->buflen0;
    ptr->delay_buflen1 = ptr->buflen0 / 3;
    ptr->delay_buflen2 = 2 * ptr->buflen0 / 3;


    for (sample_index = 0; sample_index < sample_count; sample_index++) {


        in = *(input++);
        in1 = push_buffer(in, ptr->delay1, ptr->delay_buflen1, &(ptr->delay_pos1));
        in2 = push_buffer(in, ptr->delay2, ptr->delay_buflen2, &(ptr->delay_pos2));

        push_buffer(in2, ptr->ring0, ptr->buflen0, &(ptr->pos0));
        push_buffer(in1, ptr->ring1, ptr->buflen1, &(ptr->pos1));
        push_buffer(in, ptr->ring2, ptr->buflen2, &(ptr->pos2));

        fragment_pos1 = (ptr->fragment_pos + ptr->buflen0 / 3) % ptr->buflen0;
        fragment_pos2 = (ptr->fragment_pos + 2 * ptr->buflen1 / 3) % ptr->buflen1;

        // printf("RING 0: %f, BUFLEN: %lu, POS0:%lu, CONTA:%lu \n", *(ptr->ring0), ptr->buflen0, ptr->pos0, ptr->buflen0 - ptr->fragment_pos - 1);

        out_0 = read_buffer(ptr->ring0, ptr->buflen0, ptr->pos0,
                    ptr->buflen0 - ptr->fragment_pos - 1);


        // printf("N PASSO\n");

        out_1 = read_buffer(ptr->ring1, ptr->buflen1, ptr->pos1,
                    ptr->buflen1 - fragment_pos1 - 1);


        out_2 = read_buffer(ptr->ring2, ptr->buflen2, ptr->pos2,
                    ptr->buflen2 - fragment_pos2 - 1);


        ptr->fragment_pos += 2;
        if (ptr->fragment_pos >= ptr->buflen0)
            ptr->fragment_pos = 0;

        arg_0 = (float)ptr->fragment_pos / (float)ptr->buflen0 * COS_TABLE_SIZE;
        am_0 = 1.0f - cos_table[arg_0];
        arg_1 = (float)fragment_pos1 / (float)ptr->buflen1 * COS_TABLE_SIZE;
        am_1 = 1.0f - cos_table[arg_1];
        arg_2 = (float)fragment_pos2 / (float)ptr->buflen2 * COS_TABLE_SIZE;
        am_2 = 1.0f - cos_table[arg_2];


        *(output++) = drylevel * in + wetlevel *
            (am_0 * out_0 + am_1 * out_1 + am_2 * out_2);
    }

}
static void
output_loop (gpointer data)
{
  GstPad *pad;
  GOmxCore *gomx;
  GOmxPort *out_port;
  GstOmxBaseFilter *self;
  GstFlowReturn ret = GST_FLOW_OK;

  pad = data;
  self = GST_OMX_BASE_FILTER (gst_pad_get_parent (pad));
  gomx = self->gomx;

  GST_LOG_OBJECT (self, "begin");

  /* do not bother if we have been setup to bail out */
  if ((ret = g_atomic_int_get (&self->last_pad_push_return)) != GST_FLOW_OK)
    goto leave;

  if (!self->ready) {
    g_error ("not ready");
    return;
  }

  out_port = self->out_port;

  if (G_LIKELY (out_port->enabled)) {
    OMX_BUFFERHEADERTYPE *omx_buffer = NULL;

    GST_LOG_OBJECT (self, "request buffer");
    omx_buffer = g_omx_port_request_buffer (out_port);

    GST_LOG_OBJECT (self, "omx_buffer: %p", omx_buffer);

    if (G_UNLIKELY (!omx_buffer)) {
      GST_WARNING_OBJECT (self, "null buffer: leaving");
      ret = GST_FLOW_WRONG_STATE;
      goto leave;
    }

    log_buffer (self, omx_buffer);

    if (G_LIKELY (omx_buffer->nFilledLen > 0)) {
      GstBuffer *buf;

#if 1
            /** @todo remove this check */
      if (G_LIKELY (self->in_port->enabled)) {
        GstCaps *caps = NULL;

        caps = gst_pad_get_negotiated_caps (self->srcpad);

#ifdef ANDROID
        if (!caps || gomx->settings_changed) {
#else
        if (!caps) {
#endif
                    /** @todo We shouldn't be doing this. */
          GST_WARNING_OBJECT (self, "faking settings changed notification");
          if (gomx->settings_changed_cb)
            gomx->settings_changed_cb (gomx);
#ifdef ANDROID
          gomx->settings_changed = FALSE;
#endif
        } else {
          GST_LOG_OBJECT (self, "caps already fixed: %" GST_PTR_FORMAT, caps);
          gst_caps_unref (caps);
        }
      }
#endif

      /* buf is always null when the output buffer pointer isn't shared. */
      buf = omx_buffer->pAppPrivate;

            /** @todo we need to move all the caps handling to one single
             * place, in the output loop probably. */
      if (G_UNLIKELY (omx_buffer->nFlags & 0x80)) {
        GstCaps *caps = NULL;
        GstStructure *structure;
        GValue value = { 0, {{0}
            }
        };

        caps = gst_pad_get_negotiated_caps (self->srcpad);
        caps = gst_caps_make_writable (caps);
        structure = gst_caps_get_structure (caps, 0);

        g_value_init (&value, GST_TYPE_BUFFER);
        buf = gst_buffer_new_and_alloc (omx_buffer->nFilledLen);
        memcpy (GST_BUFFER_DATA (buf),
            omx_buffer->pBuffer + omx_buffer->nOffset, omx_buffer->nFilledLen);
        gst_value_set_buffer (&value, buf);
        gst_buffer_unref (buf);
        gst_structure_set_value (structure, "codec_data", &value);
        g_value_unset (&value);

        gst_pad_set_caps (self->srcpad, caps);
      } else if (buf && !(omx_buffer->nFlags & OMX_BUFFERFLAG_EOS)) {
        GST_BUFFER_SIZE (buf) = omx_buffer->nFilledLen;
        if (self->use_timestamps) {
          GST_BUFFER_TIMESTAMP (buf) =
              gst_util_uint64_scale_int (omx_buffer->nTimeStamp, GST_SECOND,
              OMX_TICKS_PER_SECOND);
        }

        omx_buffer->pAppPrivate = NULL;
        omx_buffer->pBuffer = NULL;

        ret = push_buffer (self, buf);

        gst_buffer_unref (buf);
      } else {
        /* This is only meant for the first OpenMAX buffers,
         * which need to be pre-allocated. */
        /* Also for the very last one. */
        ret = gst_pad_alloc_buffer_and_set_caps (self->srcpad,
            GST_BUFFER_OFFSET_NONE,
            omx_buffer->nFilledLen, GST_PAD_CAPS (self->srcpad), &buf);

        if (G_LIKELY (buf)) {
          memcpy (GST_BUFFER_DATA (buf),
              omx_buffer->pBuffer + omx_buffer->nOffset,
              omx_buffer->nFilledLen);
          if (self->use_timestamps) {
            GST_BUFFER_TIMESTAMP (buf) =
                gst_util_uint64_scale_int (omx_buffer->nTimeStamp, GST_SECOND,
                OMX_TICKS_PER_SECOND);
          }

          if (self->share_output_buffer) {
            GST_WARNING_OBJECT (self, "couldn't zero-copy");
            /* If pAppPrivate is NULL, it means it was a dummy
             * allocation, free it. */
            if (!omx_buffer->pAppPrivate) {
              g_free (omx_buffer->pBuffer);
              omx_buffer->pBuffer = NULL;
            }
          }

          ret = push_buffer (self, buf);
        } else {
          GST_WARNING_OBJECT (self, "couldn't allocate buffer of size %lu",
              omx_buffer->nFilledLen);
        }
      }
    } else {
      GST_WARNING_OBJECT (self, "empty buffer");
    }

    if (self->share_output_buffer &&
        !omx_buffer->pBuffer && omx_buffer->nOffset == 0) {
      GstBuffer *buf;
      GstFlowReturn result;

      GST_LOG_OBJECT (self, "allocate buffer");
      result = gst_pad_alloc_buffer_and_set_caps (self->srcpad,
          GST_BUFFER_OFFSET_NONE,
          omx_buffer->nAllocLen, GST_PAD_CAPS (self->srcpad), &buf);

      if (G_LIKELY (result == GST_FLOW_OK)) {
        gst_buffer_ref (buf);
        omx_buffer->pAppPrivate = buf;

        omx_buffer->pBuffer = GST_BUFFER_DATA (buf);
        omx_buffer->nAllocLen = GST_BUFFER_SIZE (buf);
      } else {
        GST_WARNING_OBJECT (self,
            "could not pad allocate buffer, using malloc");
        omx_buffer->pBuffer = g_malloc (omx_buffer->nAllocLen);
      }
    }

    if (self->share_output_buffer && !omx_buffer->pBuffer) {
      GST_ERROR_OBJECT (self, "no input buffer to share");
    }

    if (G_UNLIKELY (omx_buffer->nFlags & OMX_BUFFERFLAG_EOS)) {
      GST_DEBUG_OBJECT (self, "got eos");
      gst_pad_push_event (self->srcpad, gst_event_new_eos ());
      omx_buffer->nFlags &= ~OMX_BUFFERFLAG_EOS;
      ret = GST_FLOW_UNEXPECTED;
    }

    omx_buffer->nFilledLen = 0;
    GST_LOG_OBJECT (self, "release_buffer");
    g_omx_port_release_buffer (out_port, omx_buffer);
  }

leave:

  self->last_pad_push_return = ret;

  if (gomx->omx_error != OMX_ErrorNone)
    ret = GST_FLOW_ERROR;

  if (ret != GST_FLOW_OK) {
    GST_INFO_OBJECT (self, "pause task, reason:  %s", gst_flow_get_name (ret));
    gst_pad_pause_task (self->srcpad);
  }

  GST_LOG_OBJECT (self, "end");

  gst_object_unref (self);
}

static GstFlowReturn
pad_chain (GstPad * pad, GstBuffer * buf)
{
  GOmxCore *gomx;
  GOmxPort *in_port;
  GstOmxBaseFilter *self;
  GstFlowReturn ret = GST_FLOW_OK;

  self = GST_OMX_BASE_FILTER (GST_OBJECT_PARENT (pad));

  gomx = self->gomx;

  GST_LOG_OBJECT (self, "begin");
  GST_LOG_OBJECT (self, "gst_buffer: size=%u", GST_BUFFER_SIZE (buf));

  GST_LOG_OBJECT (self, "state: %d", gomx->omx_state);

  if (G_UNLIKELY (gomx->omx_state == OMX_StateLoaded)) {
    g_mutex_lock (self->ready_lock);

    GST_INFO_OBJECT (self, "omx: prepare");

        /** @todo this should probably go after doing preparations. */
    if (self->omx_setup) {
      self->omx_setup (self);
    }

    setup_ports (self);

    g_omx_core_prepare (self->gomx);

    if (gomx->omx_state == OMX_StateIdle) {
      self->ready = TRUE;
      GST_INFO_OBJECT (self, "start srcpad task");
      gst_pad_start_task (self->srcpad, output_loop, self->srcpad);
    }

    g_mutex_unlock (self->ready_lock);

    if (gomx->omx_state != OMX_StateIdle)
      goto out_flushing;
  }

#ifdef ANDROID
  if (gomx->settings_changed) {
    GST_DEBUG_OBJECT (self, "settings changed called from streaming thread... Android");
    if (gomx->settings_changed_cb)
      gomx->settings_changed_cb (gomx);

    gomx->settings_changed = FALSE;
  }
#endif

  in_port = self->in_port;

  if (G_LIKELY (in_port->enabled)) {
    guint buffer_offset = 0;

    if (G_UNLIKELY (gomx->omx_state == OMX_StateIdle)) {
      GST_INFO_OBJECT (self, "omx: play");
      g_omx_core_start (gomx);

      if (gomx->omx_state != OMX_StateExecuting)
        goto out_flushing;

      /* send buffer with codec data flag */
            /** @todo move to util */
      if (self->codec_data) {
        OMX_BUFFERHEADERTYPE *omx_buffer;

        GST_LOG_OBJECT (self, "request buffer");
        omx_buffer = g_omx_port_request_buffer (in_port);

        if (G_LIKELY (omx_buffer)) {
          omx_buffer->nFlags |= 0x00000080;     /* codec data flag */

          omx_buffer->nFilledLen = GST_BUFFER_SIZE (self->codec_data);
          memcpy (omx_buffer->pBuffer + omx_buffer->nOffset,
              GST_BUFFER_DATA (self->codec_data), omx_buffer->nFilledLen);

          GST_LOG_OBJECT (self, "release_buffer");
          g_omx_port_release_buffer (in_port, omx_buffer);
        }
      }
    }

    if (G_UNLIKELY (gomx->omx_state != OMX_StateExecuting)) {
      GST_ERROR_OBJECT (self, "Whoa! very wrong");
    }

    while (G_LIKELY (buffer_offset < GST_BUFFER_SIZE (buf))) {
      OMX_BUFFERHEADERTYPE *omx_buffer;

      if (self->last_pad_push_return != GST_FLOW_OK ||
          !(gomx->omx_state == OMX_StateExecuting ||
              gomx->omx_state == OMX_StatePause)) {
        goto out_flushing;
      }

      GST_LOG_OBJECT (self, "request buffer");
      omx_buffer = g_omx_port_request_buffer (in_port);

      GST_LOG_OBJECT (self, "omx_buffer: %p", omx_buffer);

      if (G_LIKELY (omx_buffer)) {
        log_buffer (self, omx_buffer);

        if (omx_buffer->nOffset == 0 && self->share_input_buffer) {
          {
            GstBuffer *old_buf;
            old_buf = omx_buffer->pAppPrivate;

            if (old_buf) {
              gst_buffer_unref (old_buf);
            } else if (omx_buffer->pBuffer) {
              g_free (omx_buffer->pBuffer);
            }
          }

          omx_buffer->pBuffer = GST_BUFFER_DATA (buf);
          omx_buffer->nAllocLen = GST_BUFFER_SIZE (buf);
          omx_buffer->nFilledLen = GST_BUFFER_SIZE (buf);
          omx_buffer->pAppPrivate = buf;
        } else {
          omx_buffer->nFilledLen = MIN (GST_BUFFER_SIZE (buf) - buffer_offset,
              omx_buffer->nAllocLen - omx_buffer->nOffset);
          memcpy (omx_buffer->pBuffer + omx_buffer->nOffset,
              GST_BUFFER_DATA (buf) + buffer_offset, omx_buffer->nFilledLen);
        }

        if (self->use_timestamps) {
          GstClockTime timestamp_offset = 0;

          if (buffer_offset && GST_BUFFER_DURATION (buf) != GST_CLOCK_TIME_NONE) {
            timestamp_offset = gst_util_uint64_scale_int (buffer_offset,
                GST_BUFFER_DURATION (buf), GST_BUFFER_SIZE (buf));
          }

          omx_buffer->nTimeStamp =
              gst_util_uint64_scale_int (GST_BUFFER_TIMESTAMP (buf) +
              timestamp_offset, OMX_TICKS_PER_SECOND, GST_SECOND);
        }

        buffer_offset += omx_buffer->nFilledLen;
#ifdef ANDROID
        omx_buffer->nFlags |= OMX_BUFFERFLAG_ENDOFFRAME;
        log_buffer (self, omx_buffer);
#endif

        GST_LOG_OBJECT (self, "release_buffer");
                /** @todo untaint buffer */
        g_omx_port_release_buffer (in_port, omx_buffer);
      } else {
        GST_WARNING_OBJECT (self, "null buffer");
        ret = GST_FLOW_WRONG_STATE;
        goto out_flushing;
      }
    }
  } else {
    GST_WARNING_OBJECT (self, "done");
    ret = GST_FLOW_UNEXPECTED;
  }

  if (!self->share_input_buffer) {
    gst_buffer_unref (buf);
  }

leave:

  GST_LOG_OBJECT (self, "end");

  return ret;

  /* special conditions */
out_flushing:
  {
    const gchar *error_msg = NULL;

    if (gomx->omx_error) {
      error_msg = "Error from OpenMAX component";
    } else if (gomx->omx_state != OMX_StateExecuting &&
        gomx->omx_state != OMX_StatePause) {
      error_msg = "OpenMAX component in wrong state";
    }

    if (error_msg) {
      GST_ELEMENT_ERROR (self, STREAM, FAILED, (NULL), ("%s", error_msg));
      ret = GST_FLOW_ERROR;
    }

    gst_buffer_unref (buf);

    goto leave;
  }
}
Beispiel #25
0
void 
run_adding_DeEsser(LADSPA_Handle Instance,
		   unsigned long SampleCount) {
  
	DeEsser * ptr = (DeEsser *)Instance;

	LADSPA_Data * input = ptr->input;
	LADSPA_Data * output = ptr->output;
	LADSPA_Data threshold = LIMIT(*(ptr->threshold),-50.0f,10.0f);
	LADSPA_Data freq = LIMIT(*(ptr->freq),2000.0f,16000.0f);
	LADSPA_Data sidechain = LIMIT(*(ptr->sidechain),0.0f,1.0f);
	LADSPA_Data monitor = LIMIT(*(ptr->monitor),0.0f,1.0f);
	unsigned long sample_index;

	LADSPA_Data in = 0;
	LADSPA_Data out = 0;
	LADSPA_Data sidech = 0;
	LADSPA_Data ampl_db = 0.0f;
	LADSPA_Data attn = 0.0f;
	LADSPA_Data max_attn = 0.0f;


	if (ptr->old_freq != freq) {
		lp_set_params(&ptr->sidech_lo_filter, freq, SIDECH_BW, ptr->sample_rate);
		hp_set_params(&ptr->sidech_hi_filter, freq, SIDECH_BW, ptr->sample_rate);
		ptr->old_freq = freq;
	}

	for (sample_index = 0; sample_index < SampleCount; sample_index++) {

		in = *(input++);

		/* process sidechain filters */
		sidech = biquad_run(&ptr->sidech_hi_filter, in);
		if (sidechain > 0.1f)
			sidech = biquad_run(&ptr->sidech_lo_filter, sidech);

		ampl_db = 20.0f * log10f(sidech);
		if (ampl_db <= threshold)
			attn = 0.0f;
		else
			attn = -0.5f * (ampl_db - threshold);

		ptr->sum += attn;
		ptr->sum -= push_buffer(attn, ptr->ringbuffer, ptr->buflen, &ptr->pos);

		if (-1.0f * ptr->sum > max_attn)
			max_attn = -0.01f * ptr->sum;

		in *= db2lin(ptr->sum / 100.0f);


		/* output selector */
		if (monitor > 0.1f)
			out = sidech;
		else
			out = in;

		*(output++) += ptr->run_adding_gain * out;
		*(ptr->attenuat) = LIMIT(max_attn,0,10);
	}
}
Beispiel #26
0
void 
run_adding_Pitch(LADSPA_Handle Instance,
                 unsigned long SampleCount) {
  
	Pitch * ptr = (Pitch *)Instance;
	LADSPA_Data * input = ptr->input;
	LADSPA_Data * output = ptr->output;
	LADSPA_Data drylevel = db2lin(LIMIT(*(ptr->drylevel),-90.0f,20.0f));
	LADSPA_Data wetlevel = 0.333333f * db2lin(LIMIT(*(ptr->wetlevel),-90.0f,20.0f));
	LADSPA_Data buflen = ptr->buflen / 2.0f;
	LADSPA_Data semitone = LIMIT(*(ptr->semitone),-12.0f,12.0f);
	LADSPA_Data rate; 
	LADSPA_Data r;
	LADSPA_Data depth;

	unsigned long sample_index;
	unsigned long sample_count = SampleCount;
	
	LADSPA_Data in = 0.0f;
	LADSPA_Data sign = 1.0f;
	LADSPA_Data phase_0 = 0.0f;
	LADSPA_Data phase_am_0 = 0.0f;
	LADSPA_Data phase_1 = 0.0f;
	LADSPA_Data phase_am_1 = 0.0f;
	LADSPA_Data phase_2 = 0.0f;
	LADSPA_Data phase_am_2 = 0.0f;
	LADSPA_Data fpos_0 = 0.0f, fpos_1 = 0.0f, fpos_2 = 0.0f;
	LADSPA_Data n_0 = 0.0f, n_1 = 0.0f, n_2 = 0.0f;
	LADSPA_Data rem_0 = 0.0f, rem_1 = 0.0f, rem_2 = 0.0f;
	LADSPA_Data sa_0, sb_0, sa_1, sb_1, sa_2, sb_2;


	if (semitone == 0.0f)
		rate = LIMIT(*(ptr->rate),-50.0f,100.0f);
	else
		rate = 100.0f * (powf(ROOT_12_2,semitone) - 1.0f);
	
	r = -1.0f * ABS(rate);
	depth = buflen * LIMIT(ABS(r) / 100.0f, 0.0f, 1.0f);
	

	if (rate > 0.0f)
		sign = -1.0f;

	for (sample_index = 0; sample_index < sample_count; sample_index++) {

		in = *(input++);

		phase_0 = COS_TABLE_SIZE * PM_FREQ * sample_index / ptr->sample_rate + ptr->phase;
		while (phase_0 >= COS_TABLE_SIZE)
		        phase_0 -= COS_TABLE_SIZE;
		phase_am_0 = phase_0 + COS_TABLE_SIZE/2;
		while (phase_am_0 >= COS_TABLE_SIZE)
			phase_am_0 -= COS_TABLE_SIZE;

		phase_1 = phase_0 + COS_TABLE_SIZE/3.0f;
		while (phase_1 >= COS_TABLE_SIZE)
		        phase_1 -= COS_TABLE_SIZE;
		phase_am_1 = phase_1 + COS_TABLE_SIZE/2;
		while (phase_am_1 >= COS_TABLE_SIZE)
			phase_am_1 -= COS_TABLE_SIZE;

		phase_2 = phase_0 + 2.0f*COS_TABLE_SIZE/3.0f;
		while (phase_2 >= COS_TABLE_SIZE)
		        phase_2 -= COS_TABLE_SIZE;
		phase_am_2 = phase_2 + COS_TABLE_SIZE/2;
		while (phase_am_2 >= COS_TABLE_SIZE)
			phase_am_2 -= COS_TABLE_SIZE;

		push_buffer(in, ptr->ringbuffer, ptr->buflen, &(ptr->pos));

		fpos_0 = depth * (1.0f - sign * (2.0f * phase_0 / COS_TABLE_SIZE - 1.0f));
		n_0 = floorf(fpos_0);
		rem_0 = fpos_0 - n_0;

		fpos_1 = depth * (1.0f - sign * (2.0f * phase_1 / COS_TABLE_SIZE - 1.0f));
		n_1 = floorf(fpos_1);
		rem_1 = fpos_1 - n_1;

		fpos_2 = depth * (1.0f - sign * (2.0f * phase_2 / COS_TABLE_SIZE - 1.0f));
		n_2 = floorf(fpos_2);
		rem_2 = fpos_2 - n_2;

		sa_0 = read_buffer(ptr->ringbuffer, ptr->buflen, ptr->pos, (unsigned long) n_0);
		sb_0 = read_buffer(ptr->ringbuffer, ptr->buflen, ptr->pos, (unsigned long) n_0 + 1);

		sa_1 = read_buffer(ptr->ringbuffer, ptr->buflen, ptr->pos, (unsigned long) n_1);
		sb_1 = read_buffer(ptr->ringbuffer, ptr->buflen, ptr->pos, (unsigned long) n_1 + 1);

		sa_2 = read_buffer(ptr->ringbuffer, ptr->buflen, ptr->pos, (unsigned long) n_2);
		sb_2 = read_buffer(ptr->ringbuffer, ptr->buflen, ptr->pos, (unsigned long) n_2 + 1);

		*(output++) += ptr->run_adding_gain *
			wetlevel *
			((1.0f + cos_table[(unsigned long) phase_am_0]) *
			 ((1 - rem_0) * sa_0 + rem_0 * sb_0) +
			 (1.0f + cos_table[(unsigned long) phase_am_1]) *
			 ((1 - rem_1) * sa_1 + rem_1 * sb_1) +
			 (1.0f + cos_table[(unsigned long) phase_am_2]) *
			 ((1 - rem_2) * sa_2 + rem_2 * sb_2)) +
			drylevel *
			read_buffer(ptr->ringbuffer, ptr->buflen, ptr->pos, (unsigned long) depth);

	}

	ptr->phase += COS_TABLE_SIZE * PM_FREQ * sample_index / ptr->sample_rate;
	while (ptr->phase >= COS_TABLE_SIZE)
		ptr->phase -= COS_TABLE_SIZE;

	*(ptr->latency) = buflen - (unsigned long) depth;
}
Beispiel #27
0
int
main(int argc, char* argv[], char *envp[])
{
	int ch, count;
	read_buf buf;
	buf.size = 0;
	buf.len = 0;
	char buffer[buffer_size];
	char pass[buffer_size];
	char passtmp[buffer_size];
	opt_flag opt;
	opt.salt = NULL;
        FILE* fd;
	opt.pflag = 0;
	opt.eflag = 0;
	opt.dflag = 0;
	char* p=NULL;

	/*Get control terminal, to avoid the output redirection*/
	fd = fopen("/dev/tty","w");
	if(fd==NULL)
	{
		perror("fopen");
		exit(EXIT_FAILURE);
	}

	while ((ch = getopt(argc, argv, "dehp:s:")) != -1) {
		switch (ch) {
		case 'd':
			opt.dflag = 1;
			opt.eflag = 0;
			break;
		case 'e':
			opt.eflag = 1;
			opt.dflag = 0;
			break;
		case '?':
		case 'h':
			opt.hflag = 1;
			display_usage();
			exit(EXIT_SUCCESS);
			break;
		case 'p':
			opt.pflag = 1;
			p = optarg;
			strcpy(opt.psphase, optarg);
			break;
		case 's':
			opt.sflag = 1;
			checksalt(optarg, &opt, fd);
			break;
		default: //no option
			fprintf(fd, "Try 'aed -h' for more information.\n");
			exit(EXIT_FAILURE);
			break;
		}
	}

	while((count = read(STDIN_FILENO, buffer, buffer_size-1)) > 0)
	{
		push_buffer(&buf, buffer, count);
	}
	freopen("/dev/tty", "r", stdin); 

	if(opt.pflag)
	{
		memset(p, '*', strlen(p)); 
	}
        else if(!opt.pflag && opt.eflag)
	{
	passphase:
                fprintf(fd,"Please enter the passphase for encryption: \n");
                fflush(stdout);
		fgets(pass, buffer_size, stdin);
		pass[strlen(pass)-1]='\0'; /*delete the new line*/
                fprintf(fd,"Please reenter the passphase: \n");
                fflush(stdout);
		fgets(passtmp,  buffer_size-1, stdin);
		passtmp[strlen(passtmp)-1]='\0';
		if(strcmp(pass, passtmp) == 0)
		{
			strcpy(opt.psphase, pass);
		}
		else
		{
			fprintf(fd, "Passphases mismatch, please try again.\n");
			goto passphase;
		}
	}
	else if((!opt.pflag) && opt.dflag)
	{
                fprintf(fd,"Please enter the passphase for decryption: \n");
                fflush(stdout);
		fgets(pass, buffer_size, stdin);
		pass[strlen(pass)-1]='\0';
		strcpy(opt.psphase, pass);
	}

	de_encryption(&opt, &buf);

	return EXIT_SUCCESS;
}
Beispiel #28
0
void 
run_adding_Doubler(LADSPA_Handle Instance,
		   unsigned long SampleCount) {
  
	Doubler * ptr = (Doubler *)Instance;

	LADSPA_Data pitch = LIMIT(*(ptr->pitch),0.0f,1.0f) + 0.75f;
	LADSPA_Data depth = LIMIT(((1.0f - LIMIT(*(ptr->pitch),0.0f,1.0f)) * 1.75f + 0.25f) *
				  ptr->sample_rate / 6000.0f / M_PI,
				  0, ptr->buflen_L / 2);
	LADSPA_Data time = LIMIT(*(ptr->time), 0.0f, 1.0f) + 0.5f;
	LADSPA_Data drylevel = db2lin(LIMIT(*(ptr->drylevel),-90.0f,20.0f));
	LADSPA_Data wetlevel = db2lin(LIMIT(*(ptr->wetlevel),-90.0f,20.0f));
	LADSPA_Data dryposl = 1.0f - LIMIT(*(ptr->dryposl), 0.0f, 1.0f);
	LADSPA_Data dryposr = LIMIT(*(ptr->dryposr), 0.0f, 1.0f);
	LADSPA_Data wetposl = 1.0f - LIMIT(*(ptr->wetposl), 0.0f, 1.0f);
	LADSPA_Data wetposr = LIMIT(*(ptr->wetposr), 0.0f, 1.0f);
	LADSPA_Data * input_L = ptr->input_L;
	LADSPA_Data * input_R = ptr->input_R;
	LADSPA_Data * output_L = ptr->output_L;
	LADSPA_Data * output_R = ptr->output_R;

	unsigned long sample_index;
	unsigned long sample_count = SampleCount;

	LADSPA_Data in_L = 0.0f;
	LADSPA_Data in_R = 0.0f;
	LADSPA_Data out_L = 0.0f;
	LADSPA_Data out_R = 0.0f;

	LADSPA_Data fpos = 0.0f;
	LADSPA_Data n = 0.0f;
	LADSPA_Data rem = 0.0f;
	LADSPA_Data s_a_L, s_a_R, s_b_L, s_b_R;
	LADSPA_Data prev_p_pitch = 0.0f;
	LADSPA_Data prev_p_delay = 0.0f;
	LADSPA_Data delay;

	LADSPA_Data drystream_L = 0.0f;
	LADSPA_Data drystream_R = 0.0f;
	LADSPA_Data wetstream_L = 0.0f;
	LADSPA_Data wetstream_R = 0.0f;

	if (ptr->old_pitch != pitch) {
		ptr->pitchmod = ptr->p_pitch;
		prev_p_pitch = ptr->p_pitch;
		fractal(ptr->ring_pnoise, NOISE_LEN, pitch);
		ptr->pos_pnoise = 0;
		ptr->p_pitch = push_buffer(0.0f, ptr->ring_pnoise,
					   ptr->buflen_pnoise, &(ptr->pos_pnoise));
		ptr->d_pitch = (ptr->p_pitch - prev_p_pitch) / (float)(ptr->p_stretch);
		ptr->n_pitch = 0;

		ptr->old_pitch = pitch;
	}

	if (ptr->old_time != time) {
		ptr->delay = ptr->p_delay;
		prev_p_delay = ptr->p_delay;
		fractal(ptr->ring_dnoise, NOISE_LEN, time);
		ptr->pos_dnoise = 0;
		ptr->p_delay = push_buffer(0.0f, ptr->ring_dnoise,
					   ptr->buflen_dnoise, &(ptr->pos_dnoise));
		ptr->d_delay = (ptr->p_delay - prev_p_delay) / (float)(ptr->d_stretch);
		ptr->n_delay = 0;

		ptr->old_time = time;
	}


	for (sample_index = 0; sample_index < sample_count; sample_index++) {

		in_L = *(input_L++);
		in_R = *(input_R++);

		push_buffer(in_L, ptr->ring_L, ptr->buflen_L, &(ptr->pos_L));
		push_buffer(in_R, ptr->ring_R, ptr->buflen_R, &(ptr->pos_R));

		if (ptr->n_pitch < ptr->p_stretch) {
			ptr->pitchmod += ptr->d_pitch;
			ptr->n_pitch++;
		} else {
			ptr->pitchmod = ptr->p_pitch;
			prev_p_pitch = ptr->p_pitch;
			if (!ptr->pos_pnoise) {
				fractal(ptr->ring_pnoise, NOISE_LEN, pitch);
			}
			ptr->p_pitch = push_buffer(0.0f, ptr->ring_pnoise,
						   ptr->buflen_pnoise, &(ptr->pos_pnoise));
			ptr->d_pitch = (ptr->p_pitch - prev_p_pitch) / (float)(ptr->p_stretch);
			ptr->n_pitch = 0;
		}

		if (ptr->n_delay < ptr->d_stretch) {
			ptr->delay += ptr->d_delay;
			ptr->n_delay++;
		} else {
			ptr->delay = ptr->p_delay;
			prev_p_delay = ptr->p_delay;
			if (!ptr->pos_dnoise) {
				fractal(ptr->ring_dnoise, NOISE_LEN, time);
			}
			ptr->p_delay = push_buffer(0.0f, ptr->ring_dnoise,
						   ptr->buflen_dnoise, &(ptr->pos_dnoise));
			ptr->d_delay = (ptr->p_delay - prev_p_delay) / (float)(ptr->d_stretch);
			ptr->n_delay = 0;
		}

		delay = (12.5f * ptr->delay + 37.5f) * ptr->sample_rate / 1000.0f;
		fpos = ptr->buflen_L - depth * (1.0f - ptr->pitchmod) - delay - 1.0f;
		n = floorf(fpos);
		rem = fpos - n;

		s_a_L = read_buffer(ptr->ring_L, ptr->buflen_L,
				    ptr->pos_L, (unsigned long) n);
		s_b_L = read_buffer(ptr->ring_L, ptr->buflen_L,
				    ptr->pos_L, (unsigned long) n + 1);

		s_a_R = read_buffer(ptr->ring_R, ptr->buflen_R,
				    ptr->pos_R, (unsigned long) n);
		s_b_R = read_buffer(ptr->ring_R, ptr->buflen_R,
				    ptr->pos_R, (unsigned long) n + 1);

		drystream_L = drylevel * in_L;
		drystream_R = drylevel * in_R;
		wetstream_L = wetlevel * ((1 - rem) * s_a_L + rem * s_b_L);
		wetstream_R = wetlevel * ((1 - rem) * s_a_R + rem * s_b_R);

		out_L = dryposl * drystream_L + (1.0f - dryposr) * drystream_R +
			wetposl * wetstream_L + (1.0f - wetposr) * wetstream_R;
		out_R = (1.0f - dryposl) * drystream_L + dryposr * drystream_R +
			(1.0f - wetposl) * wetstream_L + wetposr * wetstream_R;

		*(output_L++) += ptr->run_adding_gain * out_L;
		*(output_R++) += ptr->run_adding_gain * out_R;
	}
}
Beispiel #29
0
static void
output_loop (gpointer data)
{
    GstPad *pad;
    GOmxCore *gomx;
    GOmxPort *out_port;
    GstOmxBaseFilter *self;
    GstFlowReturn ret = GST_FLOW_OK;

    pad = data;
    self = GST_OMX_BASE_FILTER (gst_pad_get_parent (pad));
    gomx = self->gomx;

    GST_LOG_OBJECT (self, "begin");

    if (!self->ready)
    {
        g_error ("not ready");
        return;
    }

    out_port = self->out_port;

    if (G_LIKELY (out_port->enabled))
    {
        OMX_BUFFERHEADERTYPE *omx_buffer = NULL;

        GST_LOG_OBJECT (self, "request buffer");
        omx_buffer = g_omx_port_request_buffer (out_port);

        GST_LOG_OBJECT (self, "omx_buffer: %p", omx_buffer);

        if (G_UNLIKELY (!omx_buffer))
        {
            GST_WARNING_OBJECT (self, "null buffer: leaving");
            ret = GST_FLOW_WRONG_STATE;
            goto leave;
        }

        GST_DEBUG_OBJECT (self, "omx_buffer: size=%lu, len=%lu, flags=%lu, offset=%lu, timestamp=%lld",
                          omx_buffer->nAllocLen, omx_buffer->nFilledLen, omx_buffer->nFlags,
                          omx_buffer->nOffset, omx_buffer->nTimeStamp);

        if (G_LIKELY (omx_buffer->nFilledLen > 0))
        {
            GstBuffer *buf;

#if 1
            /** @todo remove this check */
            if (G_LIKELY (self->in_port->enabled))
            {
                GstCaps *caps = NULL;

                caps = gst_pad_get_negotiated_caps (self->srcpad);

                if (!caps)
                {
                    /** @todo We shouldn't be doing this. */
                    GST_WARNING_OBJECT (self, "faking settings changed notification");
                    if (gomx->settings_changed_cb)
                        gomx->settings_changed_cb (gomx);
                }
                else
                {
                    GST_LOG_OBJECT (self, "caps already fixed: %" GST_PTR_FORMAT, caps);
                    gst_caps_unref (caps);
                }
            }
#endif

            /* buf is always null when the output buffer pointer isn't shared. */
            buf = omx_buffer->pAppPrivate;

            /** @todo we need to move all the caps handling to one single
             * place, in the output loop probably. */
            if (G_UNLIKELY (omx_buffer->nFlags & 0x80))
            {
                GstCaps *caps = NULL;
                GstStructure *structure;
                GValue value = { 0 };

                caps = gst_pad_get_negotiated_caps (self->srcpad);
                caps = gst_caps_make_writable (caps);
                structure = gst_caps_get_structure (caps, 0);

                g_value_init (&value, GST_TYPE_BUFFER);
                buf = gst_buffer_new_and_alloc (omx_buffer->nFilledLen);
                memcpy (GST_BUFFER_DATA (buf), omx_buffer->pBuffer + omx_buffer->nOffset, omx_buffer->nFilledLen);
                gst_value_set_buffer (&value, buf);
                gst_buffer_unref (buf);
                gst_structure_set_value (structure, "codec_data", &value);
                g_value_unset (&value);

                gst_pad_set_caps (self->srcpad, caps);
            }
            else if (buf && !(omx_buffer->nFlags & OMX_BUFFERFLAG_EOS))
            {
                GST_BUFFER_SIZE (buf) = omx_buffer->nFilledLen;
                if (self->use_timestamps)
                {
                    GST_BUFFER_TIMESTAMP (buf) = gst_util_uint64_scale_int (omx_buffer->nTimeStamp,
                                                                            GST_SECOND,
                                                                            OMX_TICKS_PER_SECOND);
                }

                omx_buffer->pAppPrivate = NULL;
                omx_buffer->pBuffer = NULL;

                ret = push_buffer (self, buf);

                gst_buffer_unref (buf);
            }
            else
            {
                /* This is only meant for the first OpenMAX buffers,
                 * which need to be pre-allocated. */
                /* Also for the very last one. */
                ret = gst_pad_alloc_buffer_and_set_caps (self->srcpad,
                                                         GST_BUFFER_OFFSET_NONE,
                                                         omx_buffer->nFilledLen,
                                                         GST_PAD_CAPS (self->srcpad),
                                                         &buf);

                if (G_LIKELY (buf))
                {
                    memcpy (GST_BUFFER_DATA (buf), omx_buffer->pBuffer + omx_buffer->nOffset, omx_buffer->nFilledLen);
                    if (self->use_timestamps)
                    {
                        GST_BUFFER_TIMESTAMP (buf) = gst_util_uint64_scale_int (omx_buffer->nTimeStamp,
                                                                                GST_SECOND,
                                                                                OMX_TICKS_PER_SECOND);
                    }

                    if (self->share_output_buffer)
                    {
                        GST_WARNING_OBJECT (self, "couldn't zero-copy");
                        /* If pAppPrivate is NULL, it means it was a dummy
                         * allocation, free it. */
                        if (!omx_buffer->pAppPrivate)
                        {
                            g_free (omx_buffer->pBuffer);
                            omx_buffer->pBuffer = NULL;
                        }
                    }

                    ret = push_buffer (self, buf);
                }
                else
                {
                    GST_WARNING_OBJECT (self, "couldn't allocate buffer of size %d",
                                        omx_buffer->nFilledLen);
                }
            }
        }
        else
        {
            GST_WARNING_OBJECT (self, "empty buffer");
        }

        if (G_UNLIKELY (omx_buffer->nFlags & OMX_BUFFERFLAG_EOS))
        {
            GST_DEBUG_OBJECT (self, "got eos");
            gst_pad_push_event (self->srcpad, gst_event_new_eos ());
            ret = GST_FLOW_UNEXPECTED;
            goto leave;
        }

        if (self->share_output_buffer &&
            !omx_buffer->pBuffer &&
            omx_buffer->nOffset == 0)
        {
            GstBuffer *buf;
            GstFlowReturn result;

            GST_LOG_OBJECT (self, "allocate buffer");
            result = gst_pad_alloc_buffer_and_set_caps (self->srcpad,
                                                        GST_BUFFER_OFFSET_NONE,
                                                        omx_buffer->nAllocLen,
                                                        GST_PAD_CAPS (self->srcpad),
                                                        &buf);

            if (G_LIKELY (result == GST_FLOW_OK))
            {
                gst_buffer_ref (buf);
                omx_buffer->pAppPrivate = buf;

                omx_buffer->pBuffer = GST_BUFFER_DATA (buf);
                omx_buffer->nAllocLen = GST_BUFFER_SIZE (buf);
            }
            else
            {
                GST_WARNING_OBJECT (self, "could not pad allocate buffer, using malloc");
                omx_buffer->pBuffer = g_malloc (omx_buffer->nAllocLen);
            }
        }

        if (self->share_output_buffer &&
            !omx_buffer->pBuffer)
        {
            GST_ERROR_OBJECT (self, "no input buffer to share");
        }

        omx_buffer->nFilledLen = 0;
        GST_LOG_OBJECT (self, "release_buffer");
        g_omx_port_release_buffer (out_port, omx_buffer);
    }

leave:

    self->last_pad_push_return = ret;

    if (gomx->omx_error != OMX_ErrorNone)
        ret = GST_FLOW_ERROR;

    if (ret != GST_FLOW_OK)
    {
        GST_INFO_OBJECT (self, "pause task, reason:  %s",
                         gst_flow_get_name (ret));
        gst_pad_pause_task (self->srcpad);
    }

    GST_LOG_OBJECT (self, "end");

    gst_object_unref (self);
}