mirror of
https://github.com/clangen/musikcube.git
synced 2025-01-30 06:32:36 +00:00
Added IPcmVisualizer, ISpectrumVisualizer and a very simple facade to
access them called Visualizer. Tweaked Player.cpp to use Visualizer and pump audio data to the selected plugin if one is available.
This commit is contained in:
parent
1b7ed8ad64
commit
c2e519ca8c
@ -37,7 +37,7 @@
|
||||
#include <core/sdk/IDecoderFactory.h>
|
||||
|
||||
class M4aDecoderFactory : public musik::core::audio::IDecoderFactory {
|
||||
public:
|
||||
public:
|
||||
M4aDecoderFactory();
|
||||
virtual ~M4aDecoderFactory();
|
||||
|
||||
|
@ -36,6 +36,7 @@
|
||||
|
||||
#include <core/debug.h>
|
||||
#include <core/audio/Player.h>
|
||||
#include <core/audio/Visualizer.h>
|
||||
#include <core/plugin/PluginFactory.h>
|
||||
#include <algorithm>
|
||||
|
||||
@ -47,7 +48,6 @@ using std::min;
|
||||
using std::max;
|
||||
|
||||
static std::string TAG = "Player";
|
||||
static float fft[FFT_N];
|
||||
|
||||
PlayerPtr Player::Create(const std::string &url, OutputPtr output) {
|
||||
return PlayerPtr(new Player(url, output));
|
||||
@ -77,6 +77,8 @@ Player::Player(const std::string &url, OutputPtr output)
|
||||
, setPosition(-1) {
|
||||
musik::debug::info(TAG, "new instance created");
|
||||
|
||||
this->spectrum = new float[FFT_N];
|
||||
|
||||
/* we allow callers to specify an output device; but if they don't,
|
||||
we will create and manage our own. */
|
||||
if (!this->output) {
|
||||
@ -96,6 +98,9 @@ Player::~Player() {
|
||||
}
|
||||
|
||||
this->thread->join();
|
||||
|
||||
delete[] this->spectrum;
|
||||
this->spectrum = nullptr;
|
||||
}
|
||||
|
||||
void Player::Play() {
|
||||
@ -306,7 +311,13 @@ void Player::OnBufferProcessed(IBuffer *buffer) {
|
||||
bool started = false;
|
||||
bool found = false;
|
||||
|
||||
buffer->Fft(fft, FFT_N);
|
||||
if (vis::SpectrumVisualizer()) {
|
||||
buffer->Fft(this->spectrum, FFT_N);
|
||||
vis::SpectrumVisualizer()->Write(this->spectrum, FFT_N);
|
||||
}
|
||||
else if (vis::PcmVisualizer()) {
|
||||
vis::PcmVisualizer()->Write(buffer);
|
||||
}
|
||||
|
||||
{
|
||||
boost::mutex::scoped_lock lock(this->queueMutex);
|
||||
|
@ -119,6 +119,7 @@ namespace musik { namespace core { namespace audio {
|
||||
double setPosition;
|
||||
int state;
|
||||
bool notifiedStarted;
|
||||
float* spectrum;
|
||||
};
|
||||
|
||||
} } }
|
||||
|
97
src/core/audio/Visualizer.cpp
Normal file
97
src/core/audio/Visualizer.cpp
Normal file
@ -0,0 +1,97 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2007-2016 musikcube team
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// * Neither the name of the author nor the names of other contributors may
|
||||
// be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "pch.hpp"
|
||||
#include "Visualizer.h"
|
||||
#include <core/plugin/PluginFactory.h>
|
||||
|
||||
#include <atomic>
|
||||
|
||||
using namespace musik::core::audio;
|
||||
|
||||
static std::vector<std::shared_ptr<ISpectrumVisualizer> > spectrumVisualizers;
|
||||
static std::vector<std::shared_ptr<IPcmVisualizer> > pcmVisualizers;
|
||||
static std::atomic<bool> initialized;
|
||||
|
||||
namespace musik {
|
||||
namespace core {
|
||||
namespace audio {
|
||||
namespace vis {
|
||||
static void init() {
|
||||
{
|
||||
typedef PluginFactory::DestroyDeleter<ISpectrumVisualizer> Deleter;
|
||||
|
||||
spectrumVisualizers = PluginFactory::Instance()
|
||||
.QueryInterface<ISpectrumVisualizer, Deleter>("GetSpectrumVisualizer");
|
||||
}
|
||||
|
||||
{
|
||||
typedef PluginFactory::DestroyDeleter<IPcmVisualizer> Deleter;
|
||||
|
||||
pcmVisualizers = PluginFactory::Instance()
|
||||
.QueryInterface<IPcmVisualizer, Deleter>("GetPcmVisualizer");
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
ISpectrumVisualizer* SpectrumVisualizer() {
|
||||
if (!initialized) {
|
||||
init();
|
||||
}
|
||||
|
||||
if (spectrumVisualizers.size()) {
|
||||
return spectrumVisualizers[0].get();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
IPcmVisualizer* PcmVisualizer() {
|
||||
if (!initialized) {
|
||||
init();
|
||||
}
|
||||
|
||||
if (pcmVisualizers.size()) {
|
||||
return pcmVisualizers[0].get();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
46
src/core/audio/Visualizer.h
Normal file
46
src/core/audio/Visualizer.h
Normal file
@ -0,0 +1,46 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2007-2016 musikcube team
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// * Neither the name of the author nor the names of other contributors may
|
||||
// be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <core/config.h>
|
||||
#include <sdk/ISpectrumVisualizer.h>
|
||||
#include <sdk/IPcmVisualizer.h>
|
||||
|
||||
namespace musik { namespace core { namespace audio { namespace vis {
|
||||
|
||||
ISpectrumVisualizer* SpectrumVisualizer();
|
||||
IPcmVisualizer* PcmVisualizer();
|
||||
|
||||
} } } }
|
@ -85,6 +85,7 @@
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="audio\GaplessTransport.cpp" />
|
||||
<ClCompile Include="audio\Visualizer.cpp" />
|
||||
<ClCompile Include="debug.cpp" />
|
||||
<ClCompile Include="io\DataStreamFactory.cpp" />
|
||||
<ClCompile Include="io\LocalFileStream.cpp" />
|
||||
@ -116,6 +117,7 @@
|
||||
<ItemGroup>
|
||||
<ClInclude Include="audio\GaplessTransport.h" />
|
||||
<ClInclude Include="audio\ITransport.h" />
|
||||
<ClInclude Include="audio\Visualizer.h" />
|
||||
<ClInclude Include="debug.h" />
|
||||
<ClInclude Include="io\DataStreamFactory.h" />
|
||||
<ClInclude Include="io\LocalFileStream.h" />
|
||||
@ -145,6 +147,7 @@
|
||||
<ClInclude Include="sdk\IMetadataReader.h" />
|
||||
<ClInclude Include="sdk\IOutput.h" />
|
||||
<ClInclude Include="sdk\IBufferProvider.h" />
|
||||
<ClInclude Include="sdk\IPcmVisualizer.h" />
|
||||
<ClInclude Include="sdk\IPlugin.h" />
|
||||
<ClInclude Include="sdk\IMetadataWriter.h" />
|
||||
<ClInclude Include="db\Connection.h" />
|
||||
@ -154,6 +157,7 @@
|
||||
<ClInclude Include="audio\Buffer.h" />
|
||||
<ClInclude Include="audio\Player.h" />
|
||||
<ClInclude Include="audio\Stream.h" />
|
||||
<ClInclude Include="sdk\ISpectrumVisualizer.h" />
|
||||
<ClInclude Include="support\Common.h" />
|
||||
<ClInclude Include="support\NonLibraryTrackHelper.h" />
|
||||
<ClInclude Include="support\PreferenceKeys.h" />
|
||||
|
@ -112,6 +112,9 @@
|
||||
<ClCompile Include="support\PreferenceKeys.cpp">
|
||||
<Filter>src\support</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="audio\Visualizer.cpp">
|
||||
<Filter>src\audio</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="pch.hpp">
|
||||
@ -249,5 +252,14 @@
|
||||
<ClInclude Include="support\PreferenceKeys.h">
|
||||
<Filter>src\support</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="sdk\IPcmVisualizer.h">
|
||||
<Filter>src\sdk</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="sdk\ISpectrumVisualizer.h">
|
||||
<Filter>src\sdk</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="audio\Visualizer.h">
|
||||
<Filter>src\audio</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
48
src/core/sdk/IPcmVisualizer.h
Normal file
48
src/core/sdk/IPcmVisualizer.h
Normal file
@ -0,0 +1,48 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2007-2016 musikcube team
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// * Neither the name of the author nor the names of other contributors may
|
||||
// be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "IBuffer.h"
|
||||
|
||||
namespace musik { namespace core { namespace audio {
|
||||
|
||||
class IPcmVisualizer {
|
||||
public:
|
||||
virtual void Destroy() = 0;
|
||||
virtual void Write(musik::core::audio::IBuffer *target) = 0;
|
||||
};
|
||||
|
||||
} } }
|
||||
|
50
src/core/sdk/ISpectrumVisualizer.h
Normal file
50
src/core/sdk/ISpectrumVisualizer.h
Normal file
@ -0,0 +1,50 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2007-2016 musikcube team
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// * Neither the name of the author nor the names of other contributors may
|
||||
// be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "config.h"
|
||||
#include "IMetadataWriter.h"
|
||||
#include "IBuffer.h"
|
||||
|
||||
namespace musik { namespace core { namespace audio {
|
||||
|
||||
class ISpectrumVisualizer {
|
||||
public:
|
||||
virtual void Destroy() = 0;
|
||||
virtual bool Write(float *spectrum, int size) = 0;
|
||||
};
|
||||
|
||||
} } }
|
||||
|
Loading…
x
Reference in New Issue
Block a user