Commit ee2cc699 authored by Stephane Letz's avatar Stephane Letz
Browse files

Cleanup audio mixing code.

parent 671ad8f8
......@@ -41,46 +41,44 @@ static void AudioBufferInit(void* buffer, size_t buffer_size, jack_nframes_t)
static inline void MixAudioBuffer(jack_default_audio_sample_t* mixbuffer, jack_default_audio_sample_t* buffer, jack_nframes_t frames)
{
#ifdef __APPLE__
// It seems that a vector mult only operation does not exist...
jack_default_audio_sample_t gain = jack_default_audio_sample_t(1.0);
vDSP_vsma(buffer, 1, &gain, mixbuffer, 1, mixbuffer, 1, frames);
vDSP_vadd(buffer, 1, mixbuffer, 1, mixbuffer, 1, frames);
#else
jack_nframes_t frames_group = frames / 4;
frames = frames % 4;
while (frames_group > 0) {
#if defined (__SSE__) && !defined (__sun__)
#if defined (__SSE__) && !defined (__sun__)
__m128 vec = _mm_add_ps(_mm_load_ps(mixbuffer), _mm_load_ps(buffer));
_mm_store_ps(mixbuffer, vec);
mixbuffer += 4;
buffer += 4;
frames_group--;
#else
register jack_default_audio_sample_t mixFloat1 = *mixbuffer;
register jack_default_audio_sample_t sourceFloat1 = *buffer;
register jack_default_audio_sample_t mixFloat2 = *(mixbuffer + 1);
register jack_default_audio_sample_t sourceFloat2 = *(buffer + 1);
register jack_default_audio_sample_t mixFloat3 = *(mixbuffer + 2);
register jack_default_audio_sample_t sourceFloat3 = *(buffer + 2);
register jack_default_audio_sample_t mixFloat4 = *(mixbuffer + 3);
register jack_default_audio_sample_t sourceFloat4 = *(buffer + 3);
buffer += 4;
frames_group--;
mixFloat1 += sourceFloat1;
mixFloat2 += sourceFloat2;
mixFloat3 += sourceFloat3;
mixFloat4 += sourceFloat4;
*mixbuffer = mixFloat1;
*(mixbuffer + 1) = mixFloat2;
*(mixbuffer + 2) = mixFloat3;
*(mixbuffer + 3) = mixFloat4;
mixbuffer += 4;
#endif
#else
register jack_default_audio_sample_t mixFloat1 = *mixbuffer;
register jack_default_audio_sample_t sourceFloat1 = *buffer;
register jack_default_audio_sample_t mixFloat2 = *(mixbuffer + 1);
register jack_default_audio_sample_t sourceFloat2 = *(buffer + 1);
register jack_default_audio_sample_t mixFloat3 = *(mixbuffer + 2);
register jack_default_audio_sample_t sourceFloat3 = *(buffer + 2);
register jack_default_audio_sample_t mixFloat4 = *(mixbuffer + 3);
register jack_default_audio_sample_t sourceFloat4 = *(buffer + 3);
buffer += 4;
frames_group--;
mixFloat1 += sourceFloat1;
mixFloat2 += sourceFloat2;
mixFloat3 += sourceFloat3;
mixFloat4 += sourceFloat4;
*mixbuffer = mixFloat1;
*(mixbuffer + 1) = mixFloat2;
*(mixbuffer + 2) = mixFloat3;
*(mixbuffer + 3) = mixFloat4;
mixbuffer += 4;
#endif
}
while (frames > 0) {
......@@ -104,11 +102,10 @@ static void AudioBufferMixdown(void* mixbuffer, void** src_buffers, int src_coun
jack_nframes_t frames_group = nframes / 4;
jack_nframes_t remaining_frames = nframes % 4;
jack_default_audio_sample_t * source = static_cast<jack_default_audio_sample_t*>(src_buffers[0]);
jack_default_audio_sample_t * target = static_cast<jack_default_audio_sample_t*>(mixbuffer);
jack_default_audio_sample_t* source = static_cast<jack_default_audio_sample_t*>(src_buffers[0]);
jack_default_audio_sample_t* target = static_cast<jack_default_audio_sample_t*>(mixbuffer);
while (frames_group > 0)
{
while (frames_group > 0) {
__m128 vec = _mm_load_ps(source);
_mm_store_ps(target, vec);
source += 4;
......@@ -116,8 +113,9 @@ static void AudioBufferMixdown(void* mixbuffer, void** src_buffers, int src_coun
--frames_group;
}
for (jack_nframes_t i = 0; i != remaining_frames; ++i)
for (jack_nframes_t i = 0; i != remaining_frames; ++i) {
target[i] = source[i];
}
#else
memcpy(mixbuffer, src_buffers[0], nframes * sizeof(jack_default_audio_sample_t));
......
......@@ -98,7 +98,7 @@ process_audio (jack_nframes_t nframes)
jack_nframes_t cur_time = jack_frame_time(client);
jack_time_t cur_micro_time = jack_get_time();
printf("jack_frame_timed %lld micro %lld delta %d\n", cur_time, (cur_micro_time - last_micro_time), cur_time - last_time);
printf("jack_frame_time %lld micro %lld delta %d\n", cur_time, (cur_micro_time - last_micro_time), cur_time - last_time);
last_time = cur_time;
last_micro_time = cur_micro_time;
*/
......
......@@ -327,6 +327,8 @@ int JackCoreAudioDriver::Read()
int JackCoreAudioDriver::Write()
{
int size = sizeof(jack_default_audio_sample_t) * fEngineControl->fBufferSize;
if (fAC3Encoder) {
// AC3 encoding and SPDIF write
......@@ -336,7 +338,7 @@ int JackCoreAudioDriver::Write()
AC3_inputs[i] = GetOutputBuffer(i);
// If not connected, clear the buffer
if (fGraphManager->GetConnectionsNum(fPlaybackPortList[i]) == 0) {
memset(AC3_inputs[i], 0, sizeof(jack_default_audio_sample_t) * fEngineControl->fBufferSize);
memset(AC3_inputs[i], 0, size);
}
}
AC3_outputs[0] = (jack_default_audio_sample_t*)fDriverOutputData->mBuffers[0].mData;
......@@ -349,14 +351,13 @@ int JackCoreAudioDriver::Write()
for (int i = 0; i < fPlaybackChannels; i++) {
if (fGraphManager->GetConnectionsNum(fPlaybackPortList[i]) > 0) {
jack_default_audio_sample_t* buffer = GetOutputBuffer(i);
int size = sizeof(jack_default_audio_sample_t) * fEngineControl->fBufferSize;
memcpy((jack_default_audio_sample_t*)fDriverOutputData->mBuffers[i].mData, buffer, size);
// Monitor ports
if (fWithMonitorPorts && fGraphManager->GetConnectionsNum(fMonitorPortList[i]) > 0) {
memcpy(GetMonitorBuffer(i), buffer, size);
}
} else {
memset((jack_default_audio_sample_t*)fDriverOutputData->mBuffers[i].mData, 0, sizeof(jack_default_audio_sample_t) * fEngineControl->fBufferSize);
memset((jack_default_audio_sample_t*)fDriverOutputData->mBuffers[i].mData, 0, size);
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment