[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r4185 - in gnuradio/branches/developers/brickle/jack/g
From: |
brickle |
Subject: |
[Commit-gnuradio] r4185 - in gnuradio/branches/developers/brickle/jack/gr-audio-jack: . src |
Date: |
Fri, 22 Dec 2006 22:46:49 -0700 (MST) |
Author: brickle
Date: 2006-12-22 22:46:49 -0700 (Fri, 22 Dec 2006)
New Revision: 4185
Modified:
gnuradio/branches/developers/brickle/jack/gr-audio-jack/AUTHORS
gnuradio/branches/developers/brickle/jack/gr-audio-jack/src/audio_jack_sink.cc
gnuradio/branches/developers/brickle/jack/gr-audio-jack/src/audio_jack_sink.h
gnuradio/branches/developers/brickle/jack/gr-audio-jack/src/audio_jack_source.cc
gnuradio/branches/developers/brickle/jack/gr-audio-jack/src/audio_jack_source.h
Log:
finishing sink
Modified: gnuradio/branches/developers/brickle/jack/gr-audio-jack/AUTHORS
===================================================================
--- gnuradio/branches/developers/brickle/jack/gr-audio-jack/AUTHORS
2006-12-22 03:08:20 UTC (rev 4184)
+++ gnuradio/branches/developers/brickle/jack/gr-audio-jack/AUTHORS
2006-12-23 05:46:49 UTC (rev 4185)
@@ -1 +1,2 @@
+Frank Brickle <address@hidden>
Stephane Fillod <address@hidden>
Modified:
gnuradio/branches/developers/brickle/jack/gr-audio-jack/src/audio_jack_sink.cc
===================================================================
---
gnuradio/branches/developers/brickle/jack/gr-audio-jack/src/audio_jack_sink.cc
2006-12-22 03:08:20 UTC (rev 4184)
+++
gnuradio/branches/developers/brickle/jack/gr-audio-jack/src/audio_jack_sink.cc
2006-12-23 05:46:49 UTC (rev 4185)
@@ -32,15 +32,11 @@
#include <stdexcept>
#include <gri_jack.h>
-#ifndef NO_PTHREAD
-#include <pthread.h>
-#endif
+#include <audio_jack_mgr.h>
typedef jack_default_audio_sample_t sample_t;
-
// Number of jack buffers in the ringbuffer
-// TODO: make it to match at least the quantity of items passed by work()
static const unsigned int N_BUFFERS = 16;
static std::string
@@ -49,46 +45,14 @@
return gr_prefs::singleton()->get_string("audio_jack",
"default_output_device", "gr_sink");
}
-int
-jack_sink_process (jack_nframes_t nframes, void *arg)
-{
- audio_jack_sink *self = (audio_jack_sink *)arg;
- unsigned int read_size = nframes*sizeof(sample_t);
-
- if (jack_ringbuffer_read_space (self->d_ringbuffer) < read_size) {
- self->d_nunderuns++;
- // FIXME: move this fputs out, we shouldn't use blocking calls in process()
- fputs ("jU", stderr);
- return 0;
- }
-
- char *buffer = (char *) jack_port_get_buffer (self->d_jack_output_port,
nframes);
-
- jack_ringbuffer_read (self->d_ringbuffer, buffer, read_size);
-
-#ifndef NO_PTHREAD
- // Tell the sink thread there is room in the ringbuffer.
- // If it is already running, the lock will not be available.
- // We can't wait here in the process() thread, but we don't
- // need to signal in that case, because the sink thread will
- // check for room availability.
-
- if (pthread_mutex_trylock (&self->d_jack_process_lock) == 0) {
- pthread_cond_signal (&self->d_ringbuffer_ready);
- pthread_mutex_unlock (&self->d_jack_process_lock);
- }
-#endif
-
- return 0;
-}
-
// ----------------------------------------------------------------
audio_jack_sink_sptr
audio_jack_make_sink(int sampling_rate, const std::string dev, bool
ok_to_block)
{
- return audio_jack_sink_sptr (new audio_jack_sink (sampling_rate, dev,
- ok_to_block));
+ return audio_jack_sink_sptr(new audio_jack_sink(sampling_rate,
+ dev,
+ ok_to_block));
}
audio_jack_sink::audio_jack_sink (int sampling_rate,
@@ -97,135 +61,77 @@
: gr_sync_block ("audio_jack_sink",
gr_make_io_signature (0, 0, 0),
gr_make_io_signature (0, 0, 0)),
- d_sampling_rate (sampling_rate),
- d_device_name (device_name.empty() ? default_device_name() : device_name),
+ d_device_name(device_name.empty() ? default_device_name() : device_name),
d_ok_to_block (ok_to_block),
- d_jack_client (0),
- d_ringbuffer (0),
- d_nunderuns (0)
+ d_ringbuffer_ready(1, 1)
{
-#ifndef NO_PTHREAD
- pthread_cond_init(&d_ringbuffer_ready, NULL);;
- pthread_mutex_init(&d_jack_process_lock, NULL);
-#endif
+ d_jack_sample_rate = audio_jack_mgr::singleton()->sample_rate();
+ d_jack_buffer_size = audio_jack_mgr::singleton()->buffer_size();
- // try to become a client of the JACK server
- if ((d_jack_client = jack_client_new (d_device_name.c_str ())) == 0) {
- fprintf (stderr, "audio_jack_sink[%s]: jack server not running?\n",
- d_device_name.c_str());
- throw std::runtime_error ("audio_jack_sink");
- }
-
- // tell the JACK server to call `jack_sink_process()' whenever
- // there is work to be done.
- jack_set_process_callback (d_jack_client, &jack_sink_process, (void*)this);
-
- // tell the JACK server to call `jack_shutdown()' if
- // it ever shuts down, either entirely, or if it
- // just decides to stop calling us.
-
- //jack_on_shutdown (d_jack_client, &jack_shutdown, (void*)this);
-
- d_jack_output_port =
- jack_port_register (d_jack_client, "out",
- JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
-
-
- d_jack_buffer_size = jack_get_buffer_size (d_jack_client);
-
- set_output_multiple (d_jack_buffer_size);
-
d_ringbuffer =
- jack_ringbuffer_create (N_BUFFERS*d_jack_buffer_size*sizeof(sample_t));
+ jack_ringbuffer_create(N_BUFFERS * d_jack_buffer_size * sizeof(sample_t));
if (d_ringbuffer == NULL)
- bail ("jack_ringbuffer_create failed", 0);
+ bail("jack_ringbuffer_create failed", 0);
- assert(sizeof(float)==sizeof(sample_t));
- set_input_signature (gr_make_io_signature (1, 1, sizeof (sample_t)));
+ d_id_from_mgr =
+ audio_jack_mgr::singleton()->register_sink(name,
+ d_ringbuffer,
+ &d_ringbuffer_ready);
-
- jack_nframes_t sample_rate = jack_get_sample_rate (d_jack_client);
-
- if ((jack_nframes_t)sampling_rate != sample_rate){
- fprintf (stderr, "audio_jack_sink[%s]: unable to support sampling rate
%d\n",
- d_device_name.c_str (), sampling_rate);
- fprintf (stderr, " card requested %d instead.\n", sample_rate);
- }
+ set_output_multiple(d_jack_buffer_size);
+ set_input_signature(gr_make_io_signature (1, 1, sizeof (sample_t)));
}
-
bool
audio_jack_sink::check_topology (int ninputs, int noutputs)
{
- if (ninputs != 1)
- return false;
-
- // tell the JACK server that we are ready to roll
- if (jack_activate (d_jack_client))
- throw std::runtime_error ("audio_jack_sink");
-
return true;
}
-audio_jack_sink::~audio_jack_sink ()
+audio_jack_sink::~audio_jack_sink()
{
- jack_client_close (d_jack_client);
- jack_ringbuffer_free (d_ringbuffer);
+ audio_jack_mgr::singleton()->unregister_sink(d_id_from_manager);
+ jack_ringbuffer_free(d_ringbuffer);
}
int
-audio_jack_sink::work (int noutput_items,
- gr_vector_const_void_star &input_items,
- gr_vector_void_star &output_items)
+audio_jack_sink::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
{
- // write_size and work_size are in bytes
- int work_size = noutput_items*sizeof(sample_t);
- unsigned int write_size;
+ float *in = (float *) input_items[0];
+ int k = 0;
- while (work_size > 0) {
- unsigned int write_space; // bytes
+ while (k < noutput_items) {
+ int nframes = jack_ringbuffer_write_space(d_ringbuffer) / sizeof(sample_t);
-#ifdef NO_PTHREAD
- while ((write_space=jack_ringbuffer_write_space (d_ringbuffer)) <
- d_jack_buffer_size*sizeof(sample_t)) {
-
usleep(1000000*((d_jack_buffer_size-write_space/sizeof(sample_t))/d_sampling_rate));
+ if (nframes == 0) { // no data right now...
+ if (d_ok_to_block) {
+ d_ringbuffer_ready.wait(); // block here, then try again
+ continue;
+ } else
+ return noutput_items;
}
-#else
- // JACK actually requires POSIX
- pthread_mutex_lock (&d_jack_process_lock);
- while ((write_space=jack_ringbuffer_write_space (d_ringbuffer)) <
- d_jack_buffer_size*sizeof(sample_t)) {
-
- // wait until jack_sink_process() signals more room
- pthread_cond_wait (&d_ringbuffer_ready, &d_jack_process_lock);
- }
- pthread_mutex_unlock (&d_jack_process_lock);
-#endif
-
- write_space -= write_space%(d_jack_buffer_size*sizeof(sample_t));
- write_size = std::min(write_space, (unsigned int)work_size);
-
- if (jack_ringbuffer_write (d_ringbuffer, (char *) input_items[0],
- write_size) < write_size) {
- bail ("jack_ringbuffer_write failed", 0);
- }
- work_size -= write_size;
+ // We can read the smaller of the request and what's in the buffer.
+ int nf = std::min(noutput_items - k, nframes);
+ jack_ringbuffer_write(d_ringbuffer, (char *) in, nf * sizeof(sample));
+ k += nf;
}
- return noutput_items;
+ return k; // tell how many we actually did
}
void
-audio_jack_sink::output_error_msg (const char *msg, int err)
+audio_jack_sink::output_error_msg(const char *msg, int err)
{
- fprintf (stderr, "audio_jack_sink[%s]: %s: %d\n",
- d_device_name.c_str (), msg, err);
+ fprintf(stderr, "audio_jack_sink[%s]: %s: %d\n",
+ d_device_name.c_str(), msg, err);
}
void
-audio_jack_sink::bail (const char *msg, int err) throw (std::runtime_error)
+audio_jack_sink::bail(const char *msg, int err) throw (std::runtime_error)
{
- output_error_msg (msg, err);
- throw std::runtime_error ("audio_jack_sink");
+ output_error_msg(msg, err);
+ throw std::runtime_error("audio_jack_sink");
}
Modified:
gnuradio/branches/developers/brickle/jack/gr-audio-jack/src/audio_jack_sink.h
===================================================================
---
gnuradio/branches/developers/brickle/jack/gr-audio-jack/src/audio_jack_sink.h
2006-12-22 03:08:20 UTC (rev 4184)
+++
gnuradio/branches/developers/brickle/jack/gr-audio-jack/src/audio_jack_sink.h
2006-12-23 05:46:49 UTC (rev 4185)
@@ -24,6 +24,7 @@
#include <gr_sync_block.h>
#include <string>
+#include <omnithread.h>
#include <jack/jack.h>
#include <jack/ringbuffer.h>
#include <stdexcept>
@@ -39,12 +40,10 @@
* \param ok_to_block
*/
audio_jack_sink_sptr
-audio_jack_make_sink (int sampling_rate,
- const std::string dev = "",
- bool ok_to_block = true);
+audio_jack_make_sink(int sampling_rate,
+ const std::string dev = "",
+ bool ok_to_block = true);
-int jack_sink_process (jack_nframes_t nframes, void *arg);
-
/*!
* \brief audio sink using JACK
*
@@ -54,29 +53,27 @@
*/
class audio_jack_sink : public gr_sync_block {
friend audio_jack_sink_sptr
- audio_jack_make_sink (int sampling_rate, const std::string device_name, bool
ok_to_block);
+ audio_jack_make_sink(int sampling_rate, const std::string device_name, bool
ok_to_block);
- friend int jack_sink_process (jack_nframes_t nframes, void *arg);
-
// typedef for pointer to class work method
- typedef int (audio_jack_sink::*work_t)(int noutput_items,
- gr_vector_const_void_star &input_items,
- gr_vector_void_star &output_items);
+ typedef int(audio_jack_sink::*work_t)(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
- unsigned int d_sampling_rate;
+ unsigned int d_sample_rate;
std::string d_device_name;
bool d_ok_to_block;
- jack_client_t *d_jack_client;
- jack_port_t *d_jack_output_port;
- jack_ringbuffer_t *d_ringbuffer;
jack_nframes_t d_jack_buffer_size;
- pthread_cond_t d_ringbuffer_ready;
- pthread_mutex_t d_jack_process_lock;
- // random stats
- int d_nunderuns; // count of underruns
+ jack_ringbuffer_t *d_ringbuffer;
+ omni_semaphore d_ringbuffer_ready;
+
+ // our position in the manager's table of sources/ports
+
+ int d_id_from_mgr;
+
void output_error_msg (const char *msg, int err);
void bail (const char *msg, int err) throw (std::runtime_error);
@@ -85,13 +82,13 @@
audio_jack_sink (int sampling_rate, const std::string device_name, bool
ok_to_block);
public:
- ~audio_jack_sink ();
+ ~audio_jack_sink();
- bool check_topology (int ninputs, int noutputs);
+ bool check_topology(int ninputs, int noutputs);
- int work (int noutput_items,
- gr_vector_const_void_star &input_items,
- gr_vector_void_star &output_items);
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
};
#endif /* INCLUDED_AUDIO_JACK_SINK_H */
Modified:
gnuradio/branches/developers/brickle/jack/gr-audio-jack/src/audio_jack_source.cc
===================================================================
---
gnuradio/branches/developers/brickle/jack/gr-audio-jack/src/audio_jack_source.cc
2006-12-22 03:08:20 UTC (rev 4184)
+++
gnuradio/branches/developers/brickle/jack/gr-audio-jack/src/audio_jack_source.cc
2006-12-23 05:46:49 UTC (rev 4185)
@@ -46,19 +46,23 @@
return gr_prefs::singleton()->get_string("audio_jack",
"default_input_device", "gr_source");
}
+// ----------------------------------------------------------------
+
audio_jack_source_sptr
-audio_jack_make_source (int sampling_rate, const std::string dev, bool
ok_to_block)
+audio_jack_make_source(int sampling_rate, const std::string dev, bool
ok_to_block)
{
- return audio_jack_source_sptr (new audio_jack_source (sampling_rate, dev,
ok_to_block));
+ return audio_jack_source_sptr(new audio_jack_source(sampling_rate,
+ dev,
+ ok_to_block));
}
-audio_jack_source::audio_jack_source (int sampling_rate,
- const std::string device_name,
- bool ok_to_block)
- : gr_sync_block ("audio_jack_source",
- gr_make_io_signature (0, 0, 0),
- gr_make_io_signature (0, 0, 0)),
- d_device_name (device_name.empty() ? default_device_name() : device_name),
+audio_jack_source::audio_jack_source(int sampling_rate,
+ const std::string device_name,
+ bool ok_to_block)
+ : gr_sync_block("audio_jack_source",
+ gr_make_io_signature (0, 0, 0),
+ gr_make_io_signature (0, 0, 0)),
+ d_device_name(device_name.empty() ? default_device_name() : device_name),
d_ok_to_block(ok_to_block),
d_ringbuffer_ready(1, 1)
{
Modified:
gnuradio/branches/developers/brickle/jack/gr-audio-jack/src/audio_jack_source.h
===================================================================
---
gnuradio/branches/developers/brickle/jack/gr-audio-jack/src/audio_jack_source.h
2006-12-22 03:08:20 UTC (rev 4184)
+++
gnuradio/branches/developers/brickle/jack/gr-audio-jack/src/audio_jack_source.h
2006-12-23 05:46:49 UTC (rev 4185)
@@ -44,8 +44,6 @@
const std::string dev = "",
bool ok_to_block = true);
-int jack_source_process (jack_nframes_t nframes, void *arg);
-
/*!
* \brief audio source using JACK
*
@@ -59,8 +57,6 @@
const std::string device_name,
bool ok_to_block);
- friend int jack_source_process (jack_nframes_t nframes, void *arg);
-
// typedef for pointer to class work method
typedef int (audio_jack_source::*work_t)(int noutput_items,
gr_vector_const_void_star
&input_items,
@@ -84,16 +80,16 @@
void bail (const char *msg, int err) throw (std::runtime_error);
protected:
- audio_jack_source (int sampling_rate, const std::string device_name, bool
ok_to_block);
+ audio_jack_source(int sampling_rate, const std::string device_name, bool
ok_to_block);
public:
- ~audio_jack_source ();
+ ~audio_jack_source();
- bool check_topology (int ninputs, int noutputs);
+ bool check_topology(int ninputs, int noutputs);
- int work (int noutput_items,
- gr_vector_const_void_star &input_items,
- gr_vector_void_star &output_items);
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
};
#endif /* INCLUDED_AUDIO_JACK_SOURCE_H */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r4185 - in gnuradio/branches/developers/brickle/jack/gr-audio-jack: . src,
brickle <=