Read the default sample rate from the selected output and relay it to

the appropriate decoder.
This commit is contained in:
casey langen 2021-09-19 21:53:02 -07:00
parent 06bdf32959
commit d99e65d91f
6 changed files with 26 additions and 14 deletions

View File

@ -39,6 +39,7 @@
#include <musikcore/sdk/IDecoder.h>
#include <musikcore/sdk/IDSP.h>
#include <musikcore/sdk/IDecoderFactory.h>
#include <musikcore/sdk/IOutput.h>
#include <list>
@ -50,7 +51,7 @@ namespace musik { namespace core { namespace audio {
virtual void OnBufferProcessedByPlayer(musik::core::sdk::IBuffer* buffer) = 0;
virtual double SetPosition(double seconds) = 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 int GetCapabilities() = 0;
virtual bool Eof() = 0;

View File

@ -296,7 +296,7 @@ void musik::core::audio::playerThreadLoop(Player* player) {
gain = player->gain.peak;
}
if (player->stream->OpenStream(player->url)) {
if (player->stream->OpenStream(player->url, player->output.get())) {
for (Listener* l : player->Listeners()) {
player->streamState = StreamState::Buffered;
l->OnPlayerBuffered(player);

View File

@ -118,7 +118,7 @@ int Stream::GetCapabilities() {
return this->capabilities;
}
bool Stream::OpenStream(std::string uri) {
bool Stream::OpenStream(std::string uri, IOutput* output) {
musik::debug::info(TAG, "opening " + uri);
/* 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);
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()) {
this->capabilities |= (int) musik::core::sdk::Capability::Prebuffer;
this->RefillInternalBuffers();

View File

@ -39,6 +39,8 @@
#include <musikcore/audio/Buffer.h>
#include <musikcore/audio/IStream.h>
#include <musikcore/sdk/IDecoder.h>
#include <musikcore/sdk/IOutput.h>
#include <musikcore/sdk/IDSP.h>
#include <musikcore/sdk/constants.h>
@ -73,15 +75,15 @@ namespace musik { namespace core { namespace audio {
public:
virtual ~Stream();
virtual IBuffer* GetNextProcessedOutputBuffer() override;
virtual void OnBufferProcessedByPlayer(IBuffer* buffer) override;
virtual double SetPosition(double seconds) override;
virtual double GetDuration() override;
virtual bool OpenStream(std::string uri) override;
virtual void Interrupt() override;
virtual int GetCapabilities() override;
virtual bool Eof() override { return this->done; }
virtual void Release() override { delete this; }
IBuffer* GetNextProcessedOutputBuffer() override;
void OnBufferProcessedByPlayer(IBuffer* buffer) override;
double SetPosition(double seconds) override;
double GetDuration() override;
bool OpenStream(std::string uri, musik::core::sdk::IOutput* output) override;
void Interrupt() override;
int GetCapabilities() override;
bool Eof() override { return this->done; }
void Release() override { delete this; }
private:
bool GetNextBufferFromDecoder();

View File

@ -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) {
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) {

View File

@ -930,7 +930,7 @@ void Indexer::RunAnalyzers() {
audio::IStreamPtr stream = audio::Stream::Create(2048, 2.0, StreamFlags::NoDSP);
if (stream) {
if (stream->OpenStream(track->Uri())) {
if (stream->OpenStream(track->Uri(), nullptr)) {
/* decode the stream quickly, passing to all analyzers */