Skip to content

Commit

Permalink
Traktor: Removed lock from BankBuffer.
Browse files Browse the repository at this point in the history
  • Loading branch information
apistol78 committed Apr 29, 2024
1 parent 4c76c33 commit 775f841
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 27 deletions.
25 changes: 7 additions & 18 deletions code/Sound/Resound/BankBuffer.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include "Core/Thread/Acquire.h"
#include "Sound/Sound.h"
#include "Sound/Resound/BankBuffer.h"
#include "Sound/Resound/IGrain.h"

namespace traktor
namespace traktor::sound
{
namespace sound
namespace
{
namespace
{

struct BankBufferCursor : public RefCountImpl< IAudioBufferCursor >
{
Expand All @@ -43,7 +40,7 @@ struct BankBufferCursor : public RefCountImpl< IAudioBufferCursor >
}
};

}
}

T_IMPLEMENT_RTTI_CLASS(L"traktor.sound.BankBuffer", BankBuffer, IAudioBuffer)

Expand All @@ -54,23 +51,20 @@ BankBuffer::BankBuffer(const RefArray< IGrain >& grains)

void BankBuffer::updateCursor(IAudioBufferCursor* cursor) const
{
T_ANONYMOUS_VAR(Acquire< Semaphore >)(m_lock);
BankBufferCursor* bankCursor = static_cast< BankBufferCursor* >(cursor);
const IGrain* currentGrain = m_grains[bankCursor->m_grainIndex];
currentGrain->updateCursor(bankCursor->m_grainCursor);
}

const IGrain* BankBuffer::getCurrentGrain(const IAudioBufferCursor* cursor) const
{
T_ANONYMOUS_VAR(Acquire< Semaphore >)(m_lock);
const BankBufferCursor* bankCursor = static_cast< const BankBufferCursor* >(cursor);
const IGrain* currentGrain = m_grains[bankCursor->m_grainIndex];
return currentGrain->getCurrentGrain(bankCursor->m_grainCursor);
}

void BankBuffer::getActiveGrains(const IAudioBufferCursor* cursor, RefArray< const IGrain >& outActiveGrains) const
{
T_ANONYMOUS_VAR(Acquire< Semaphore >)(m_lock);
const BankBufferCursor* bankCursor = static_cast< const BankBufferCursor* >(cursor);
if (bankCursor && bankCursor->m_grainCursor)
{
Expand All @@ -82,28 +76,25 @@ void BankBuffer::getActiveGrains(const IAudioBufferCursor* cursor, RefArray< con
Ref< IAudioBufferCursor > BankBuffer::createCursor() const
{
if (m_grains.empty())
return 0;
return nullptr;

Ref< BankBufferCursor > bankCursor = new BankBufferCursor();

bankCursor->m_grainIndex = 0;
bankCursor->m_grainCursor = m_grains[0]->createCursor();

return bankCursor->m_grainCursor ? bankCursor : 0;
return bankCursor->m_grainCursor ? bankCursor : nullptr;
}

bool BankBuffer::getBlock(IAudioBufferCursor* cursor, const IAudioMixer* mixer, AudioBlock& outBlock) const
{
T_ANONYMOUS_VAR(Acquire< Semaphore >)(m_lock);

BankBufferCursor* bankCursor = static_cast< BankBufferCursor* >(cursor);

int32_t ngrains = int32_t(m_grains.size());
const int32_t ngrains = int32_t(m_grains.size());
if (bankCursor->m_grainIndex >= ngrains)
return false;

Ref< IGrain > grain = m_grains[bankCursor->m_grainIndex];

for (;;)
{
if (grain->getBlock(
Expand All @@ -117,12 +108,10 @@ bool BankBuffer::getBlock(IAudioBufferCursor* cursor, const IAudioMixer* mixer,
return false;

grain = m_grains[bankCursor->m_grainIndex];

bankCursor->m_grainCursor = grain->createCursor();
}

return true;
}

}
}
12 changes: 3 additions & 9 deletions code/Sound/Resound/BankBuffer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -9,7 +9,6 @@
#pragma once

#include "Core/RefArray.h"
#include "Core/Thread/Semaphore.h"
#include "Sound/IAudioBuffer.h"

// import/export mechanism.
Expand All @@ -20,10 +19,8 @@
# define T_DLLCLASS T_DLLIMPORT
#endif

namespace traktor
namespace traktor::sound
{
namespace sound
{

class IGrain;

Expand All @@ -32,7 +29,7 @@ class T_DLLCLASS BankBuffer : public IAudioBuffer
T_RTTI_CLASS;

public:
BankBuffer(const RefArray< IGrain >& grains);
explicit BankBuffer(const RefArray< IGrain >& grains);

void updateCursor(IAudioBufferCursor* cursor) const;

Expand All @@ -46,9 +43,6 @@ class T_DLLCLASS BankBuffer : public IAudioBuffer

private:
RefArray< IGrain > m_grains;
mutable Semaphore m_lock;
};

}
}

0 comments on commit 775f841

Please sign in to comment.