mirror of
https://github.com/clangen/musikcube.git
synced 2025-03-14 13:21:13 +00:00
Fixed bug with playing audio with sample sizes != 44100 hz. Verified 192k
flac is working again!
This commit is contained in:
parent
df4f16ec14
commit
8242eda806
@ -53,10 +53,11 @@ static std::string TAG = "Stream";
|
||||
target->Copy(current->BufferPointer() + offset, count); \
|
||||
SET_OFFSET(target, offset) \
|
||||
|
||||
Stream::Stream(int samplesPerChannel, int bufferCount, unsigned int options)
|
||||
Stream::Stream(int samplesPerChannel, double bufferLengthSeconds, unsigned int options)
|
||||
: options(options)
|
||||
, samplesPerChannel(samplesPerChannel)
|
||||
, bufferCount(bufferCount)
|
||||
, bufferLengthSeconds(bufferLengthSeconds)
|
||||
, bufferCount(0)
|
||||
, decoderSampleRate(0)
|
||||
, decoderChannels(0)
|
||||
, decoderSamplePosition(0)
|
||||
@ -83,8 +84,8 @@ Stream::~Stream() {
|
||||
}
|
||||
}
|
||||
|
||||
IStreamPtr Stream::Create(int samplesPerChannel, int bufferCount, unsigned int options) {
|
||||
return IStreamPtr(new Stream(samplesPerChannel, bufferCount, options));
|
||||
IStreamPtr Stream::Create(int samplesPerChannel, double bufferLengthSeconds, unsigned int options) {
|
||||
return IStreamPtr(new Stream(samplesPerChannel, bufferLengthSeconds, options));
|
||||
}
|
||||
|
||||
double Stream::SetPosition(double requestedSeconds) {
|
||||
@ -153,12 +154,16 @@ bool Stream::GetNextBufferFromDecoder() {
|
||||
this->decoderChannels = buffer->Channels();
|
||||
|
||||
int samplesPerBuffer = samplesPerChannel * decoderChannels;
|
||||
|
||||
this->bufferCount = (int)(this->bufferLengthSeconds *
|
||||
(double)(this->decoderSampleRate / samplesPerBuffer));
|
||||
|
||||
this->rawBuffer = new float[bufferCount * samplesPerBuffer];
|
||||
int offset = 0;
|
||||
for (int i = 0; i < bufferCount; i++) {
|
||||
this->recycledBuffers.push_back(
|
||||
new Buffer(this->rawBuffer + offset, samplesPerBuffer));
|
||||
|
||||
auto buffer = new Buffer(this->rawBuffer + offset, samplesPerBuffer);
|
||||
buffer->SetSampleRate(this->decoderSampleRate);
|
||||
this->recycledBuffers.push_back(buffer);
|
||||
offset += samplesPerBuffer;
|
||||
}
|
||||
}
|
||||
@ -220,8 +225,7 @@ void Stream::RefillInternalBuffers() {
|
||||
int count = 0;
|
||||
|
||||
if (!this->rawBuffer) { /* not initialized */
|
||||
/* fill it partially so we get playing immediately */
|
||||
count = this->bufferCount / 4;
|
||||
count = -1;
|
||||
}
|
||||
else {
|
||||
/* fill another chunk -- most of the time for file-based
|
||||
@ -230,7 +234,7 @@ void Stream::RefillInternalBuffers() {
|
||||
count = std::min(recycled - 1, this->bufferCount / 4);
|
||||
}
|
||||
|
||||
while (!this->done && count > 0) {
|
||||
while (!this->done && (count > 0 || count == -1)) {
|
||||
--count;
|
||||
|
||||
/* ask the decoder for the next buffer */
|
||||
@ -239,6 +243,13 @@ void Stream::RefillInternalBuffers() {
|
||||
break;
|
||||
}
|
||||
|
||||
/* if we were just initialized, then make sure our buffer
|
||||
is about a quarter filled. this will start playback quickly,
|
||||
and ensure we don't have any buffer underruns */
|
||||
if (count < 0) {
|
||||
count = bufferCount / 4;
|
||||
}
|
||||
|
||||
Buffer* currentBuffer = this->decoderBuffer;
|
||||
|
||||
int floatsPerBuffer = this->samplesPerChannel * currentBuffer->Channels();
|
||||
|
@ -53,11 +53,11 @@ namespace musik { namespace core { namespace audio {
|
||||
public:
|
||||
static IStreamPtr Create(
|
||||
int samplesPerChannel = 2048,
|
||||
int bufferCount = 48,
|
||||
double bufferLengthSeconds = 4.5,
|
||||
unsigned int options = 0);
|
||||
|
||||
private:
|
||||
Stream(int samplesPerChannel, int bufferCount, unsigned int options);
|
||||
Stream(int samplesPerChannel, double bufferLengthSeconds, unsigned int options);
|
||||
|
||||
public:
|
||||
virtual ~Stream();
|
||||
@ -94,6 +94,7 @@ namespace musik { namespace core { namespace audio {
|
||||
int samplesPerChannel;
|
||||
int bufferCount;
|
||||
bool done;
|
||||
double bufferLengthSeconds;
|
||||
|
||||
float* rawBuffer;
|
||||
|
||||
|
@ -457,7 +457,9 @@ public class MainActivity extends WebSocketActivityBase {
|
||||
boolean isFromMemoryCache,
|
||||
boolean isFirstResource)
|
||||
{
|
||||
preloadNextImage();
|
||||
if (!isPaused()) {
|
||||
preloadNextImage();
|
||||
}
|
||||
|
||||
/* if the loadId doesn't match the current id, then the image was
|
||||
loaded for a different song. throw it away. */
|
||||
|
Loading…
x
Reference in New Issue
Block a user