diff options
author | Joerg Mueller <nexyon@gmail.com> | 2010-07-28 13:36:03 +0400 |
---|---|---|
committer | Joerg Mueller <nexyon@gmail.com> | 2010-07-28 13:36:03 +0400 |
commit | 7296600434c49b40215ba842af73a8b1517e12eb (patch) | |
tree | ba41a61f147073c91cf370c1f470b7c519397766 /intern/audaspace/jack | |
parent | 3e3f874a65e9c20353fdc26a20a2f5da9b41e90e (diff) |
Audaspace: HUGE Refactor.
Some points of the refactor not sorted by importance:
* Fixed immutability of readers and factories (there are exceptions...)
* Fixed copy constructors and = operators
* Removed messaging system
* Removed reader types
* Added const where possible
* Using initalisers when possible
* Avoided use of pointers when possible
* Removed AUD_NEW and AUD_DELETE macros
* Removed useless NULL pointer checks
* Fixed exception catching
* Fixed some yet unknown bugs
* Lots of other stuff
Diffstat (limited to 'intern/audaspace/jack')
-rw-r--r-- | intern/audaspace/jack/AUD_JackDevice.cpp | 41 | ||||
-rw-r--r-- | intern/audaspace/jack/AUD_JackDevice.h | 16 |
2 files changed, 28 insertions, 29 deletions
diff --git a/intern/audaspace/jack/AUD_JackDevice.cpp b/intern/audaspace/jack/AUD_JackDevice.cpp index ae7725be81c..08a1d5920e5 100644 --- a/intern/audaspace/jack/AUD_JackDevice.cpp +++ b/intern/audaspace/jack/AUD_JackDevice.cpp @@ -26,7 +26,6 @@ #include "AUD_Mixer.h" #include "AUD_JackDevice.h" #include "AUD_IReader.h" -#include "AUD_Buffer.h" #include <stdio.h> #include <stdlib.h> @@ -43,8 +42,8 @@ void AUD_JackDevice::updateRingBuffers() 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(); + sample_t* buffer = m_buffer.getBuffer(); + float* deinterleave = m_deinterleavebuf.getBuffer(); jack_transport_state_t state; jack_position_t position; @@ -196,7 +195,7 @@ AUD_JackDevice::AUD_JackDevice(AUD_DeviceSpecs specs, int buffersize) jack_set_sync_callback(m_client, AUD_JackDevice::jack_sync, this); // register our output channels which are called ports in jack - m_ports = new jack_port_t*[m_specs.channels]; AUD_NEW("jack_port") + m_ports = new jack_port_t*[m_specs.channels]; try { @@ -211,22 +210,22 @@ AUD_JackDevice::AUD_JackDevice(AUD_DeviceSpecs specs, int buffersize) AUD_THROW(AUD_ERROR_JACK); } } - catch(AUD_Exception) + catch(AUD_Exception&) { jack_client_close(m_client); - delete[] m_ports; AUD_DELETE("jack_port") + delete[] m_ports; throw; } m_specs.rate = (AUD_SampleRate)jack_get_sample_rate(m_client); buffersize *= sizeof(sample_t); - m_ringbuffers = new jack_ringbuffer_t*[specs.channels]; AUD_NEW("jack_buffers") + m_ringbuffers = new jack_ringbuffer_t*[specs.channels]; for(unsigned int i = 0; i < specs.channels; i++) m_ringbuffers[i] = jack_ringbuffer_create(buffersize); buffersize *= specs.channels; - m_buffer = new AUD_Buffer(buffersize); AUD_NEW("buffer"); - m_deinterleavebuf = new AUD_Buffer(buffersize); AUD_NEW("buffer"); + m_deinterleavebuf.resize(buffersize); + m_buffer.resize(buffersize); create(); @@ -238,25 +237,19 @@ AUD_JackDevice::AUD_JackDevice(AUD_DeviceSpecs specs, int buffersize) pthread_mutex_init(&m_mixingLock, NULL); pthread_cond_init(&m_mixingCondition, NULL); - try - { - // activate the client - if(jack_activate(m_client)) - AUD_THROW(AUD_ERROR_JACK); - } - catch(AUD_Exception) + // activate the client + if(jack_activate(m_client)) { jack_client_close(m_client); - delete[] m_ports; AUD_DELETE("jack_port") - delete m_buffer; AUD_DELETE("buffer"); - delete m_deinterleavebuf; AUD_DELETE("buffer"); + delete[] m_ports; for(unsigned int i = 0; i < specs.channels; i++) jack_ringbuffer_free(m_ringbuffers[i]); - delete[] m_ringbuffers; AUD_DELETE("jack_buffers") + delete[] m_ringbuffers; pthread_mutex_destroy(&m_mixingLock); pthread_cond_destroy(&m_mixingCondition); destroy(); - throw; + + AUD_THROW(AUD_ERROR_JACK); } const char** ports = jack_get_ports(m_client, NULL, NULL, @@ -284,7 +277,7 @@ AUD_JackDevice::~AUD_JackDevice() jack_client_close(m_client); m_valid = false; - delete[] m_ports; AUD_DELETE("jack_port") + delete[] m_ports; pthread_mutex_lock(&m_mixingLock); pthread_cond_signal(&m_mixingCondition); @@ -293,11 +286,9 @@ AUD_JackDevice::~AUD_JackDevice() pthread_cond_destroy(&m_mixingCondition); pthread_mutex_destroy(&m_mixingLock); - delete m_buffer; AUD_DELETE("buffer"); - delete m_deinterleavebuf; AUD_DELETE("buffer"); for(unsigned int i = 0; i < m_specs.channels; i++) jack_ringbuffer_free(m_ringbuffers[i]); - delete[] m_ringbuffers; AUD_DELETE("jack_buffers") + delete[] m_ringbuffers; destroy(); } diff --git a/intern/audaspace/jack/AUD_JackDevice.h b/intern/audaspace/jack/AUD_JackDevice.h index 58e34978c1f..abd32147246 100644 --- a/intern/audaspace/jack/AUD_JackDevice.h +++ b/intern/audaspace/jack/AUD_JackDevice.h @@ -28,7 +28,7 @@ #include "AUD_SoftwareDevice.h" -class AUD_Buffer; +#include "AUD_Buffer.h" #include <jack.h> #include <ringbuffer.h> @@ -54,9 +54,12 @@ private: /** * The output buffer. */ - AUD_Buffer* m_buffer; + AUD_Buffer m_buffer; - AUD_Buffer* m_deinterleavebuf; + /** + * The deinterleaving buffer. + */ + AUD_Buffer m_deinterleavebuf; jack_ringbuffer_t** m_ringbuffers; @@ -114,13 +117,18 @@ private: void updateRingBuffers(); + // hide copy constructor and operator= + AUD_JackDevice(const AUD_JackDevice&); + AUD_JackDevice& operator=(const AUD_JackDevice&); + protected: virtual void playing(bool playing); public: /** * Creates a Jack client for audio output. - * \param specs The wanted audio specification, where only the channel count is important. + * \param specs The wanted audio specification, where only the channel count + * is important. * \exception AUD_Exception Thrown if the audio device cannot be opened. */ AUD_JackDevice(AUD_DeviceSpecs specs, int buffersize = AUD_DEFAULT_BUFFER_SIZE); |