mirror of
https://github.com/clangen/musikcube.git
synced 2025-02-06 12:39:54 +00:00
Read the default sample rate from the selected output and relay it to
the appropriate decoder.
This commit is contained in:
parent
06bdf32959
commit
d99e65d91f
@ -39,6 +39,7 @@
|
|||||||
#include <musikcore/sdk/IDecoder.h>
|
#include <musikcore/sdk/IDecoder.h>
|
||||||
#include <musikcore/sdk/IDSP.h>
|
#include <musikcore/sdk/IDSP.h>
|
||||||
#include <musikcore/sdk/IDecoderFactory.h>
|
#include <musikcore/sdk/IDecoderFactory.h>
|
||||||
|
#include <musikcore/sdk/IOutput.h>
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
@ -50,7 +51,7 @@ namespace musik { namespace core { namespace audio {
|
|||||||
virtual void OnBufferProcessedByPlayer(musik::core::sdk::IBuffer* buffer) = 0;
|
virtual void OnBufferProcessedByPlayer(musik::core::sdk::IBuffer* buffer) = 0;
|
||||||
virtual double SetPosition(double seconds) = 0;
|
virtual double SetPosition(double seconds) = 0;
|
||||||
virtual double GetDuration() = 0;
|
virtual double GetDuration() = 0;
|
||||||
virtual bool OpenStream(std::string uri) = 0;
|
virtual bool OpenStream(std::string uri, musik::core::sdk::IOutput* output) = 0;
|
||||||
virtual void Interrupt() = 0;
|
virtual void Interrupt() = 0;
|
||||||
virtual int GetCapabilities() = 0;
|
virtual int GetCapabilities() = 0;
|
||||||
virtual bool Eof() = 0;
|
virtual bool Eof() = 0;
|
||||||
|
@ -296,7 +296,7 @@ void musik::core::audio::playerThreadLoop(Player* player) {
|
|||||||
gain = player->gain.peak;
|
gain = player->gain.peak;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player->stream->OpenStream(player->url)) {
|
if (player->stream->OpenStream(player->url, player->output.get())) {
|
||||||
for (Listener* l : player->Listeners()) {
|
for (Listener* l : player->Listeners()) {
|
||||||
player->streamState = StreamState::Buffered;
|
player->streamState = StreamState::Buffered;
|
||||||
l->OnPlayerBuffered(player);
|
l->OnPlayerBuffered(player);
|
||||||
|
@ -118,7 +118,7 @@ int Stream::GetCapabilities() {
|
|||||||
return this->capabilities;
|
return this->capabilities;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Stream::OpenStream(std::string uri) {
|
bool Stream::OpenStream(std::string uri, IOutput* output) {
|
||||||
musik::debug::info(TAG, "opening " + uri);
|
musik::debug::info(TAG, "opening " + uri);
|
||||||
|
|
||||||
/* use our file stream abstraction to open the data at the
|
/* use our file stream abstraction to open the data at the
|
||||||
@ -133,6 +133,15 @@ bool Stream::OpenStream(std::string uri) {
|
|||||||
this->decoder = streams::GetDecoderForDataStream(this->dataStream);
|
this->decoder = streams::GetDecoderForDataStream(this->dataStream);
|
||||||
|
|
||||||
if (this->decoder) {
|
if (this->decoder) {
|
||||||
|
/* if the output has a default/preferred sample rate, let the decoder know
|
||||||
|
before sending samples. this way the decoder can resample the audio itself
|
||||||
|
if it likes. */
|
||||||
|
if (output) {
|
||||||
|
int defaultOutputSampleRate = output->GetDefaultSampleRate();
|
||||||
|
if (defaultOutputSampleRate > 0) {
|
||||||
|
this->decoder->SetPreferredSampleRate(defaultOutputSampleRate);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (this->dataStream->CanPrefetch()) {
|
if (this->dataStream->CanPrefetch()) {
|
||||||
this->capabilities |= (int) musik::core::sdk::Capability::Prebuffer;
|
this->capabilities |= (int) musik::core::sdk::Capability::Prebuffer;
|
||||||
this->RefillInternalBuffers();
|
this->RefillInternalBuffers();
|
||||||
|
@ -39,6 +39,8 @@
|
|||||||
#include <musikcore/audio/Buffer.h>
|
#include <musikcore/audio/Buffer.h>
|
||||||
#include <musikcore/audio/IStream.h>
|
#include <musikcore/audio/IStream.h>
|
||||||
#include <musikcore/sdk/IDecoder.h>
|
#include <musikcore/sdk/IDecoder.h>
|
||||||
|
#include <musikcore/sdk/IOutput.h>
|
||||||
|
|
||||||
#include <musikcore/sdk/IDSP.h>
|
#include <musikcore/sdk/IDSP.h>
|
||||||
#include <musikcore/sdk/constants.h>
|
#include <musikcore/sdk/constants.h>
|
||||||
|
|
||||||
@ -73,15 +75,15 @@ namespace musik { namespace core { namespace audio {
|
|||||||
public:
|
public:
|
||||||
virtual ~Stream();
|
virtual ~Stream();
|
||||||
|
|
||||||
virtual IBuffer* GetNextProcessedOutputBuffer() override;
|
IBuffer* GetNextProcessedOutputBuffer() override;
|
||||||
virtual void OnBufferProcessedByPlayer(IBuffer* buffer) override;
|
void OnBufferProcessedByPlayer(IBuffer* buffer) override;
|
||||||
virtual double SetPosition(double seconds) override;
|
double SetPosition(double seconds) override;
|
||||||
virtual double GetDuration() override;
|
double GetDuration() override;
|
||||||
virtual bool OpenStream(std::string uri) override;
|
bool OpenStream(std::string uri, musik::core::sdk::IOutput* output) override;
|
||||||
virtual void Interrupt() override;
|
void Interrupt() override;
|
||||||
virtual int GetCapabilities() override;
|
int GetCapabilities() override;
|
||||||
virtual bool Eof() override { return this->done; }
|
bool Eof() override { return this->done; }
|
||||||
virtual void Release() override { delete this; }
|
void Release() override { delete this; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool GetNextBufferFromDecoder();
|
bool GetNextBufferFromDecoder();
|
||||||
|
@ -993,7 +993,7 @@ mcsdk_export double mcsdk_audio_stream_get_duration(mcsdk_audio_stream as) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mcsdk_export bool mcsdk_audio_stream_open_uri(mcsdk_audio_stream as, const char* uri) {
|
mcsdk_export bool mcsdk_audio_stream_open_uri(mcsdk_audio_stream as, const char* uri) {
|
||||||
return AUDIOSTREAM(as)->OpenStream(uri);
|
return AUDIOSTREAM(as)->OpenStream(uri, nullptr); /* TODO: fixme; should pass output if available */
|
||||||
}
|
}
|
||||||
|
|
||||||
mcsdk_export void mcsdk_audio_stream_interrupt(mcsdk_audio_stream as) {
|
mcsdk_export void mcsdk_audio_stream_interrupt(mcsdk_audio_stream as) {
|
||||||
|
@ -930,7 +930,7 @@ void Indexer::RunAnalyzers() {
|
|||||||
audio::IStreamPtr stream = audio::Stream::Create(2048, 2.0, StreamFlags::NoDSP);
|
audio::IStreamPtr stream = audio::Stream::Create(2048, 2.0, StreamFlags::NoDSP);
|
||||||
|
|
||||||
if (stream) {
|
if (stream) {
|
||||||
if (stream->OpenStream(track->Uri())) {
|
if (stream->OpenStream(track->Uri(), nullptr)) {
|
||||||
|
|
||||||
/* decode the stream quickly, passing to all analyzers */
|
/* decode the stream quickly, passing to all analyzers */
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user