コード例 #1
0
ファイル: input_client.c プロジェクト: adiknoth/tschack
void
jack_finish (void *arg)
{
	struct a2j* self = (struct a2j*) arg;
	void* thread_status;

        self->finishing = 1;
        
	a2j_debug("midi: delete");
	
	g_keep_alsa_walking = false;  /* tell alsa io thread to stop, whenever they wake up */
	/* do something that we need to do anyway and will wake the io thread, then join */
	snd_seq_disconnect_from (self->seq, self->port_id, SND_SEQ_CLIENT_SYSTEM, SND_SEQ_PORT_SYSTEM_ANNOUNCE);
	a2j_debug ("wait for ALSA io thread\n");
	pthread_join (self->alsa_io_thread, &thread_status);
	a2j_debug ("thread done\n");
	
	jack_ringbuffer_reset (self->port_add);
	
	a2j_stream_detach (&self->stream);
	
	snd_seq_close(self->seq);
	self->seq = NULL;
	
	a2j_stream_close (self);
	
	jack_ringbuffer_free(self->port_add);
	jack_ringbuffer_free(self->port_del);
	
	free (self);
}
コード例 #2
0
void AUD_JackDevice::updateRingBuffers()
{
	size_t size, temp;
	unsigned int samplesize = AUD_SAMPLE_SIZE(m_specs);
	unsigned int i, j;
	unsigned int channels = m_specs.channels;
	sample_t* buffer = m_buffer.getBuffer();
	float* deinterleave = m_deinterleavebuf.getBuffer();
	jack_transport_state_t state;
	jack_position_t position;

	pthread_mutex_lock(&m_mixingLock);
	while(m_valid)
	{
		if(m_sync > 1)
		{
			if(m_syncFunc)
			{
				state = jack_transport_query(m_client, &position);
				m_syncFunc(m_syncFuncData, state != JackTransportStopped, position.frame / (float) m_specs.rate);
			}

			for(i = 0; i < channels; i++)
				jack_ringbuffer_reset(m_ringbuffers[i]);
		}

		size = jack_ringbuffer_write_space(m_ringbuffers[0]);
		for(i = 1; i < channels; i++)
			if((temp = jack_ringbuffer_write_space(m_ringbuffers[i])) < size)
				size = temp;

		while(size > samplesize)
		{
			size /= samplesize;
			mix((data_t*)buffer, size);
			for(i = 0; i < channels; i++)
			{
				for(j = 0; j < size; j++)
					deinterleave[i * size + j] = buffer[i + j * channels];
				jack_ringbuffer_write(m_ringbuffers[i], (char*)(deinterleave + i * size), size * sizeof(float));
			}

			size = jack_ringbuffer_write_space(m_ringbuffers[0]);
			for(i = 1; i < channels; i++)
				if((temp = jack_ringbuffer_write_space(m_ringbuffers[i])) < size)
					size = temp;
		}

		if(m_sync > 1)
		{
			m_sync = 3;
		}

		pthread_cond_wait(&m_mixingCondition, &m_mixingLock);
	}
	pthread_mutex_unlock(&m_mixingLock);
}
コード例 #3
0
ファイル: audio_feed.c プロジェクト: gleriston/idjc
int audio_feed_process_audio(jack_nframes_t n_frames, void *arg)
    {
    struct audio_feed *self = audio_feed;
    struct threads_info *ti = self->threads_info;
    struct encoder *e;
    struct recorder *r;
    sample_t *input_port_buffer[2];
    int i;
    
    input_port_buffer[0] = jack_port_get_buffer(g.port.output_in_l, n_frames);
    input_port_buffer[1] = jack_port_get_buffer(g.port.output_in_r, n_frames);
    
    /* feed pcm audio data to all encoders that request it */
    for (i = 0; i < ti->n_encoders; i++)
        {
        e = ti->encoder[i];
        switch (e->jack_dataflow_control)
            {
            case JD_OFF:
                break;
            case JD_ON:
                while (jack_ringbuffer_write_space(e->input_rb[1]) < n_frames * sizeof (sample_t))
                    nanosleep(&(struct timespec){0, 10000000}, NULL);
                    
                jack_ringbuffer_write(e->input_rb[0], (char *)input_port_buffer[0], n_frames * sizeof (sample_t));
                jack_ringbuffer_write(e->input_rb[1], (char *)input_port_buffer[1], n_frames * sizeof (sample_t));
                break;
            case JD_FLUSH:
                jack_ringbuffer_reset(e->input_rb[0]);
                jack_ringbuffer_reset(e->input_rb[1]);
                e->jack_dataflow_control = JD_OFF;
                break;
            default:
                fprintf(stderr, "jack_process_callback: unhandled jack_dataflow_control parameter\n");
            }
        }
コード例 #4
0
ファイル: Disk_Stream.C プロジェクト: harryhaaren/non
/** flush buffers and reset. Must only be called from the RT thread. */
void
Disk_Stream::base_flush ( bool is_output )
{
//    THREAD_ASSERT( RT );

    /* flush buffers */
    for ( unsigned int i = _rb.size(); i--; )
        jack_ringbuffer_reset( _rb[ i ] );

    sem_destroy( &_blocks );
    
    if ( is_output )
        sem_init( &_blocks, 0, _total_blocks );
    else
        sem_init( &_blocks, 0, 0 );
}
コード例 #5
0
ファイル: cubeb_jack.cpp プロジェクト: camlorn/cubeb
static void
cbjack_stream_destroy(cubeb_stream * stream)
{
  AutoLock lock(stream->context->mutex);
  stream->state = STATE_INACTIVE;
  stream->ports_ready = false;

  for(unsigned int c = 0; c < stream->params.channels; c++) {
    jack_port_unregister (stream->context->jack_client, stream->output_ports[c]);
    stream->output_ports[c] = NULL;
    jack_ringbuffer_reset(stream->ringbuffer[c]);
  }

  if (stream->resampler != NULL) {
    speex_resampler_destroy(stream->resampler);
    stream->resampler = NULL;
  }
  stream->in_use = false;
}
コード例 #6
0
ファイル: jack.c プロジェクト: BG2BKK/cmus
static int op_jack_cb(jack_nframes_t frames, void *arg)
{
	size_t bytes_want = frames * sizeof(jack_default_audio_sample_t);

	if (drop) {
		for (int i = 0; i < CHANNELS; i++) {
			jack_ringbuffer_reset(ringbuffer[i]);
		}
		drop = false;
		drop_done = true;
	}

	size_t bytes_min = SIZE_MAX;
	for (int i = 0; i < CHANNELS; i++) {
		size_t bytes_available = jack_ringbuffer_read_space(ringbuffer[i]);
		if (bytes_available < bytes_min) {
			bytes_min = bytes_available;
		}
	}

	/* if there is less than frames awaylable play silence */
	if (paused || bytes_min < bytes_want) {
		for (int i = 0; i < CHANNELS; i++) {
			jack_default_audio_sample_t* jack_buf = jack_port_get_buffer(output_ports[i], frames);
			memset(jack_buf, 0, bytes_want);
		}
		return 0;
	}

	for (int i = 0; i < CHANNELS; i++) {
		jack_default_audio_sample_t* jack_buf = jack_port_get_buffer(output_ports[i], frames);
		size_t bytes_read = jack_ringbuffer_read(ringbuffer[i], (char*) jack_buf, bytes_want);

		if (bytes_read < bytes_want) {
			/* This should not happen[TM] - just in case set fail = 1 */
			d_print("underrun! wanted %zu only got %zu bytes\n", bytes_want, bytes_read);
			fail = 1;
		}
	}

	return 0;
}
コード例 #7
0
ファイル: i_jack.c プロジェクト: Jheengut/gmerlin
static int open_jack(void * data,
                     gavl_audio_format_t * format,
                     gavl_video_format_t * video_format,
                     gavl_metadata_t * m)
  {
  int i;
  jack_t * priv = data;
  if(!priv->client)
    bg_jack_open_client(priv, 0, jack_process);

  /* Copy format */
  gavl_audio_format_copy(&priv->format, format);
  
  priv->format.samplerate = priv->samplerate;
  priv->format.sample_format = GAVL_SAMPLE_FLOAT;
  priv->format.interleave_mode = GAVL_INTERLEAVE_NONE;
  priv->format.samples_per_frame = priv->samples_per_frame;

  /* TODO: Make this configurable */
  priv->format.num_channels = 2;
  
  /* Clear ports */
  for(i = 0; i < priv->num_ports; i++)
    priv->ports[i].active = 0;
  
  /* Setup ports */
  for(i = 0; i < priv->num_ports; i++)
    {
    priv->ports[i].index = i;
    priv->format.channel_locations[i] = priv->ports[i].channel_id;
    priv->ports[i].active = 1;
    jack_ringbuffer_reset(priv->ports[i].buffer);
    }

  gavl_audio_format_copy(format, &priv->format);

  priv->src = gavl_audio_source_create(read_func_jack, priv, 0, format);
  
  priv->samples_read = 0;
  return 1;
  }
コード例 #8
0
ファイル: alsa_seqmidi.c プロジェクト: Andux/jack2
static
int alsa_seqmidi_detach(alsa_midi_t *m)
{
	alsa_seqmidi_t *self = (alsa_seqmidi_t*) m;

	debug_log("midi: detach");

	if (!self->seq)
		return -EALREADY;

	alsa_seqmidi_stop(m);

	jack_ringbuffer_reset(self->port_add);
	free_ports(self, self->port_del);

	stream_detach(self, PORT_INPUT);
	stream_detach(self, PORT_OUTPUT);

	snd_seq_close(self->seq);
	self->seq = NULL;

	return 0;
}
コード例 #9
0
ファイル: vna.c プロジェクト: Split7fire/red-pitaya-notes
int main(int argc, char *argv[])
{
  int fd, sock_server, sock_client;
  pthread_t thread;
  volatile void *cfg, *sts;
  char *name = "/dev/mem";
  volatile uint32_t *rx_freq, *tx_freq;
  volatile uint32_t *rx_size, *tx_size;
  volatile int16_t *tx_level;
  volatile uint8_t *rst;
  struct sockaddr_in addr;
  uint32_t command, rate;
  int32_t value, corr;
  int64_t start, stop, size, freq;
  int i, yes = 1;

  if((fd = open(name, O_RDWR)) < 0)
  {
    perror("open");
    return EXIT_FAILURE;
  }

  sts = mmap(NULL, sysconf(_SC_PAGESIZE), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x40000000);
  cfg = mmap(NULL, sysconf(_SC_PAGESIZE), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x40001000);
  rx_data[0] = mmap(NULL, 2*sysconf(_SC_PAGESIZE), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x40002000);
  rx_data[1] = mmap(NULL, 2*sysconf(_SC_PAGESIZE), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x40004000);
  rx_data[2] = mmap(NULL, 2*sysconf(_SC_PAGESIZE), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x40006000);
  rx_freq = mmap(NULL, 16*sysconf(_SC_PAGESIZE), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x40010000);
  tx_freq = mmap(NULL, 16*sysconf(_SC_PAGESIZE), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x40020000);

  rx_cntr[0] = ((uint16_t *)(sts + 12));
  rx_cntr[1] = ((uint16_t *)(sts + 14));
  rx_cntr[2] = ((uint16_t *)(sts + 16));

  rst = ((uint8_t *)(cfg + 0));
  rx_size = ((uint32_t *)(cfg + 4));
  tx_size = ((uint32_t *)(cfg + 8));
  tx_level = ((int16_t *)(cfg + 12));

  *rx_size = 250000 - 1;
  *tx_size = 250000 - 1;
  *tx_level = 32767;

  start = 100000;
  stop = 60000000;
  size = 600;
  rate = 1;
  corr = 0;

  sweep_data = jack_ringbuffer_create(65536);

  *rst &= ~3;
  *rst |= 4;

  if((sock_server = socket(AF_INET, SOCK_STREAM, 0)) < 0)
  {
    perror("socket");
    return EXIT_FAILURE;
  }

  setsockopt(sock_server, SOL_SOCKET, SO_REUSEADDR, (void *)&yes , sizeof(yes));

  /* setup listening address */
  memset(&addr, 0, sizeof(addr));
  addr.sin_family = AF_INET;
  addr.sin_addr.s_addr = htonl(INADDR_ANY);
  addr.sin_port = htons(1001);

  if(bind(sock_server, (struct sockaddr *)&addr, sizeof(addr)) < 0)
  {
    perror("bind");
    return EXIT_FAILURE;
  }

  listen(sock_server, 1024);

  while(1)
  {
    if((sock_client = accept(sock_server, NULL, NULL)) < 0)
    {
      perror("accept");
      return EXIT_FAILURE;
    }

    while(1)
    {
      if(recv(sock_client, (char *)&command, 4, MSG_WAITALL) <= 0) break;
      value = command & 0xfffffff;
      switch(command >> 28)
      {
        case 0:
          /* set start */
          if(value < 0 || value > 62000000) continue;
          start = value;
          break;
        case 1:
          /* set stop */
          if(value < 0 || value > 62000000) continue;
          stop = value;
          break;
        case 2:
          /* set size */
          if(value < 1 || value > 16383) continue;
          size = value;
          break;
        case 3:
          /* set rate */
          if(value < 1 || value > 10000) continue;
          rate = value;
          *rx_size = 250000 * rate - 1;
          *tx_size = 250000 * rate - 1;
          break;
        case 4:
          /* set correction */
          if(value < -100000 || value > 100000) continue;
          corr = value;
          break;
        case 5:
          /* set level */
          if(value < -32767 || value > 32767) continue;
          *tx_level = value;
          break;
        case 6:
          /* sweep */
          *rst &= ~3;
          *rst |= 4;
          *rst &= ~4;
          *rst |= 2;
          rate_thread = rate;
          size_thread = size;
          sock_thread = sock_client;
          jack_ringbuffer_reset(sweep_data);
          if(pthread_create(&thread, NULL, read_handler, NULL) < 0)
          {
            perror("pthread_create");
            return EXIT_FAILURE;
          }
          pthread_detach(thread);
          if(pthread_create(&thread, NULL, send_handler, NULL) < 0)
          {
            perror("pthread_create");
            return EXIT_FAILURE;
          }
          pthread_detach(thread);
          freq = start;
          for(i = 0; i <= size; ++i)
          {
            if(i > 0) freq = start + (stop - start) * (i - 1) / (size - 1);
            freq *= (1.0 + 1.0e-9 * corr);
            *rx_freq = (uint32_t)floor((freq + 2500) / 125.0e6 * (1<<30) + 0.5);
            *tx_freq = (uint32_t)floor(freq / 125.0e6 * (1<<30) + 0.5);
          }
          *rst |= 1;
          break;
        case 7:
          /* cancel */
          *rst &= ~3;
          *rst |= 4;
          sock_thread = -1;
          break;
      }
    }

    *rst &= ~3;
    *rst |= 4;
    sock_thread = -1;
    close(sock_client);
  }

  close(sock_server);

  return EXIT_SUCCESS;
}
コード例 #10
0
ファイル: JACKAudioSource.cpp プロジェクト: Nibato/JACKplugin
void JACKAudioSource::FlushSamples()
{
	jack_ringbuffer_reset(sampleBuffer);
}
コード例 #11
0
ファイル: jackringbuffer.hpp プロジェクト: Dagal/jackcpp
			/**
			  @brief Reset

			  This is not threadsafe.  This resets the read and write pointers,
			  effectively making the ring buffer empty.
			  */
			void reset(){
				jack_ringbuffer_reset(mRingBufferPtr);
			}
コード例 #12
0
ファイル: jack.c プロジェクト: Deslon/Supernova
static void flush_jack(out123_handle *ao)
{
	jack_handle_t *handle = (jack_handle_t*)ao->userptr;
	/* Reset the ring buffers*/
	jack_ringbuffer_reset(handle->rb);
}
コード例 #13
0
ファイル: ringbuffer.c プロジェクト: stetre/luajack
int ringbuffer_creset(jack_ringbuffer_t *rbuf)
	{
	jack_ringbuffer_reset(rbuf);
	return 0;
	}