mirror of
https://github.com/clangen/musikcube.git
synced 2024-10-02 13:02:35 +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 "AlsaOut.h"
|
||||||
#include <core/sdk/constants.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_ACCESS_TYPE SND_PCM_ACCESS_RW_INTERLEAVED
|
||||||
#define PCM_FORMAT SND_PCM_FORMAT_FLOAT_LE
|
#define PCM_FORMAT SND_PCM_FORMAT_FLOAT_LE
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
#include <core/sdk/constants.h>
|
#include <core/sdk/constants.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#define BUFFER_COUNT 32
|
#define BUFFER_COUNT 16
|
||||||
|
|
||||||
using namespace musik::core::sdk;
|
using namespace musik::core::sdk;
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
#include <core/sdk/constants.h>
|
#include <core/sdk/constants.h>
|
||||||
|
|
||||||
#define MAX_VOLUME 0xFFFF
|
#define MAX_VOLUME 0xFFFF
|
||||||
#define MAX_BUFFERS_PER_OUTPUT 32
|
#define MAX_BUFFERS_PER_OUTPUT 16
|
||||||
|
|
||||||
using LockT = std::unique_lock<std::recursive_mutex>;
|
using LockT = std::unique_lock<std::recursive_mutex>;
|
||||||
|
|
||||||
|
@ -51,12 +51,12 @@ namespace musik { namespace core { namespace audio {
|
|||||||
using IDecoder = musik::core::sdk::IDecoder;
|
using IDecoder = musik::core::sdk::IDecoder;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/* note that most output devices manage 16-32 buffers internally,
|
/* note that most output devices manage 16 buffers internally,
|
||||||
so, by default, let's allocate 48 buffers worth of contiguous
|
so, by default, let's allocate 32 buffers worth of contiguous
|
||||||
memory. if we need more buffers they will be allocated dynamically */
|
memory. if we need more buffers they will be allocated dynamically */
|
||||||
static StreamPtr Create(
|
static StreamPtr Create(
|
||||||
int samplesPerChannel = 2048,
|
int samplesPerChannel = 2048,
|
||||||
int bufferCount = 48,
|
int bufferCount = 32,
|
||||||
unsigned int options = 0);
|
unsigned int options = 0);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -72,7 +72,6 @@ void MessageQueue::Dispatch() {
|
|||||||
system_clock::now().time_since_epoch());
|
system_clock::now().time_since_epoch());
|
||||||
|
|
||||||
using Iterator = std::list<EnqueuedMessage*>::iterator;
|
using Iterator = std::list<EnqueuedMessage*>::iterator;
|
||||||
std::list<EnqueuedMessage*> toDispatch;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
LockT lock(this->queueMutex);
|
LockT lock(this->queueMutex);
|
||||||
@ -88,7 +87,7 @@ void MessageQueue::Dispatch() {
|
|||||||
EnqueuedMessage *m = (*it);
|
EnqueuedMessage *m = (*it);
|
||||||
|
|
||||||
if (now >= m->time) {
|
if (now >= m->time) {
|
||||||
toDispatch.push_back(m);
|
this->dispatch.push_back(m);
|
||||||
it = this->queue.erase(it);
|
it = this->queue.erase(it);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -99,12 +98,14 @@ void MessageQueue::Dispatch() {
|
|||||||
|
|
||||||
/* dispatch outside of the critical section */
|
/* dispatch outside of the critical section */
|
||||||
|
|
||||||
Iterator it = toDispatch.begin();
|
Iterator it = this->dispatch.begin();
|
||||||
while (it != toDispatch.end()) {
|
while (it != this->dispatch.end()) {
|
||||||
this->Dispatch((*it)->message);
|
this->Dispatch((*it)->message);
|
||||||
delete *it;
|
delete *it;
|
||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->dispatch.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
int MessageQueue::Remove(IMessageTarget *target, int type) {
|
int MessageQueue::Remove(IMessageTarget *target, int type) {
|
||||||
|
@ -63,6 +63,7 @@ namespace musik { namespace core { namespace runtime {
|
|||||||
|
|
||||||
std::mutex queueMutex;
|
std::mutex queueMutex;
|
||||||
std::list<EnqueuedMessage*> queue;
|
std::list<EnqueuedMessage*> queue;
|
||||||
|
std::list<EnqueuedMessage*> dispatch;
|
||||||
std::condition_variable_any waitForDispatch;
|
std::condition_variable_any waitForDispatch;
|
||||||
|
|
||||||
void Dispatch(IMessagePtr message);
|
void Dispatch(IMessagePtr message);
|
||||||
|
Loading…
Reference in New Issue
Block a user