mirror of
https://github.com/clangen/musikcube.git
synced 2025-03-14 13:21:13 +00:00
Similar to some other micro-optimizations, don't keep recreating a new
list of messages to dispatch in MessageQueue -- create it once as a member variable and reuse. Also tweaked stream and output buffer sizes.
This commit is contained in:
parent
8f51b6c191
commit
8c4a4ab248
@ -35,7 +35,7 @@
|
||||
#include "AlsaOut.h"
|
||||
#include <core/sdk/constants.h>
|
||||
|
||||
#define BUFFER_COUNT 32
|
||||
#define BUFFER_COUNT 16
|
||||
#define PCM_ACCESS_TYPE SND_PCM_ACCESS_RW_INTERLEAVED
|
||||
#define PCM_FORMAT SND_PCM_FORMAT_FLOAT_LE
|
||||
|
||||
|
@ -36,7 +36,7 @@
|
||||
#include <core/sdk/constants.h>
|
||||
#include <iostream>
|
||||
|
||||
#define BUFFER_COUNT 32
|
||||
#define BUFFER_COUNT 16
|
||||
|
||||
using namespace musik::core::sdk;
|
||||
|
||||
|
@ -37,7 +37,7 @@
|
||||
#include <core/sdk/constants.h>
|
||||
|
||||
#define MAX_VOLUME 0xFFFF
|
||||
#define MAX_BUFFERS_PER_OUTPUT 32
|
||||
#define MAX_BUFFERS_PER_OUTPUT 16
|
||||
|
||||
using LockT = std::unique_lock<std::recursive_mutex>;
|
||||
|
||||
|
@ -51,12 +51,12 @@ namespace musik { namespace core { namespace audio {
|
||||
using IDecoder = musik::core::sdk::IDecoder;
|
||||
|
||||
public:
|
||||
/* note that most output devices manage 16-32 buffers internally,
|
||||
so, by default, let's allocate 48 buffers worth of contiguous
|
||||
/* note that most output devices manage 16 buffers internally,
|
||||
so, by default, let's allocate 32 buffers worth of contiguous
|
||||
memory. if we need more buffers they will be allocated dynamically */
|
||||
static StreamPtr Create(
|
||||
int samplesPerChannel = 2048,
|
||||
int bufferCount = 48,
|
||||
int bufferCount = 32,
|
||||
unsigned int options = 0);
|
||||
|
||||
private:
|
||||
|
@ -72,7 +72,6 @@ void MessageQueue::Dispatch() {
|
||||
system_clock::now().time_since_epoch());
|
||||
|
||||
using Iterator = std::list<EnqueuedMessage*>::iterator;
|
||||
std::list<EnqueuedMessage*> toDispatch;
|
||||
|
||||
{
|
||||
LockT lock(this->queueMutex);
|
||||
@ -88,7 +87,7 @@ void MessageQueue::Dispatch() {
|
||||
EnqueuedMessage *m = (*it);
|
||||
|
||||
if (now >= m->time) {
|
||||
toDispatch.push_back(m);
|
||||
this->dispatch.push_back(m);
|
||||
it = this->queue.erase(it);
|
||||
}
|
||||
else {
|
||||
@ -99,12 +98,14 @@ void MessageQueue::Dispatch() {
|
||||
|
||||
/* dispatch outside of the critical section */
|
||||
|
||||
Iterator it = toDispatch.begin();
|
||||
while (it != toDispatch.end()) {
|
||||
Iterator it = this->dispatch.begin();
|
||||
while (it != this->dispatch.end()) {
|
||||
this->Dispatch((*it)->message);
|
||||
delete *it;
|
||||
it++;
|
||||
}
|
||||
|
||||
this->dispatch.clear();
|
||||
}
|
||||
|
||||
int MessageQueue::Remove(IMessageTarget *target, int type) {
|
||||
|
@ -63,6 +63,7 @@ namespace musik { namespace core { namespace runtime {
|
||||
|
||||
std::mutex queueMutex;
|
||||
std::list<EnqueuedMessage*> queue;
|
||||
std::list<EnqueuedMessage*> dispatch;
|
||||
std::condition_variable_any waitForDispatch;
|
||||
|
||||
void Dispatch(IMessagePtr message);
|
||||
|
Loading…
x
Reference in New Issue
Block a user