mirror of
https://github.com/clangen/musikcube.git
synced 2025-01-05 12:54:02 +00:00
Simplified the way Buffer handles sample count. Updated decoders and output plugins accordingly.
This commit is contained in:
parent
250a265de4
commit
20cdc0d6ff
@ -69,7 +69,7 @@ double CddaDecoder::SetPosition(double seconds) {
|
||||
|
||||
bool CddaDecoder::GetBuffer(IBuffer *buffer) {
|
||||
int channels = data->GetChannelCount();
|
||||
buffer->SetSamples(CDDA_BUFFER_SIZE / BYTES_PER_RAW_SAMPLE / channels);
|
||||
buffer->SetSamples(CDDA_BUFFER_SIZE / BYTES_PER_RAW_SAMPLE);
|
||||
buffer->SetChannels(data->GetChannelCount());
|
||||
buffer->SetSampleRate(CDDA_SAMPLE_RATE);
|
||||
|
||||
@ -86,7 +86,7 @@ bool CddaDecoder::GetBuffer(IBuffer *buffer) {
|
||||
target[x] = (float) t[x] / 16384.0f;
|
||||
}
|
||||
|
||||
buffer->SetSamples(count / BYTES_PER_RAW_SAMPLE / channels);
|
||||
buffer->SetSamples(count / BYTES_PER_RAW_SAMPLE);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -234,7 +234,7 @@ bool FlacDecoder::GetBuffer(IBuffer *buffer) {
|
||||
/* read the next chunk */
|
||||
if (FLAC__stream_decoder_process_single(this->decoder)) {
|
||||
if (this->outputBuffer && this->outputBufferUsed > 0) {
|
||||
buffer->SetSamples(this->outputBufferUsed / this->channels);
|
||||
buffer->SetSamples(this->outputBufferUsed);
|
||||
copy(buffer->BufferPointer(), this->outputBuffer, this->outputBufferUsed);
|
||||
this->outputBufferUsed = 0; /* mark consumed */
|
||||
return true;
|
||||
|
@ -213,7 +213,7 @@ bool M4aDecoder::GetBuffer(IBuffer* target) {
|
||||
|
||||
target->SetSampleRate(frameInfo.samplerate);
|
||||
target->SetChannels(frameInfo.channels);
|
||||
target->SetSamples(frameInfo.samples / frameInfo.channels);
|
||||
target->SetSamples(frameInfo.samples);
|
||||
|
||||
memcpy(
|
||||
static_cast<void*>(target->BufferPointer()),
|
||||
|
@ -35,7 +35,7 @@
|
||||
#include "Mpg123Decoder.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#define STREAM_FEED_SIZE 2048 * 8
|
||||
#define STREAM_FEED_SIZE 2048 * 2
|
||||
#define DEBUG 0
|
||||
|
||||
#if DEBUG > 0
|
||||
@ -53,7 +53,7 @@ Mpg123Decoder::Mpg123Decoder()
|
||||
, fileStream(NULL)
|
||||
, lastMpg123Status(MPG123_NEED_MORE) {
|
||||
this->decoder = mpg123_new(NULL, NULL);
|
||||
this->sampleSizeBytes = this->channels * sizeof(float);
|
||||
this->sampleSizeBytes = sizeof(float);
|
||||
}
|
||||
|
||||
Mpg123Decoder::~Mpg123Decoder() {
|
||||
@ -103,7 +103,7 @@ double Mpg123Decoder::SetPosition(double second) {
|
||||
bool Mpg123Decoder::GetBuffer(IBuffer *buffer) {
|
||||
buffer->SetChannels(this->channels);
|
||||
buffer->SetSampleRate(this->sampleRate);
|
||||
buffer->SetSamples(STREAM_FEED_SIZE / this->channels);
|
||||
buffer->SetSamples(STREAM_FEED_SIZE);
|
||||
|
||||
unsigned char* targetBuffer = (unsigned char*) (buffer->BufferPointer());
|
||||
|
||||
|
@ -138,7 +138,7 @@ bool OggDecoder::GetBuffer(IBuffer *buffer) {
|
||||
vorbis_info *info = ov_info(&this->oggFile, -1);
|
||||
buffer->SetChannels(info->channels);
|
||||
buffer->SetSampleRate(info->rate);
|
||||
buffer->SetSamples(samplesRead);
|
||||
buffer->SetSamples(samplesRead * info->channels);
|
||||
|
||||
/*
|
||||
The musik audio engine expects:
|
||||
|
@ -47,7 +47,7 @@ WaveOutBuffer::WaveOutBuffer(WaveOut *waveOut, IBuffer *buffer, IBufferProvider
|
||||
}
|
||||
|
||||
void WaveOutBuffer::Initialize() {
|
||||
this->header.dwBufferLength = this->buffer->Samples() * this->buffer->Channels() * sizeof(float);
|
||||
this->header.dwBufferLength = this->buffer->Samples() * sizeof(float);
|
||||
this->header.lpData = (LPSTR) this->buffer->BufferPointer();
|
||||
this->header.dwUser = (DWORD_PTR) this;
|
||||
this->header.dwBytesRecorded = 0;
|
||||
|
@ -81,7 +81,7 @@ float* Buffer::BufferPointer() const {
|
||||
return this->buffer;
|
||||
}
|
||||
|
||||
long Buffer::Samples() const { /* pre-multiplied by channel count */
|
||||
long Buffer::Samples() const {
|
||||
return this->sampleSize;
|
||||
}
|
||||
|
||||
@ -98,21 +98,20 @@ void Buffer::CopyFormat(BufferPtr fromBuffer) {
|
||||
}
|
||||
|
||||
void Buffer::ResizeBuffer() {
|
||||
long requiredBufferSize = this->sampleSize * this->channels;
|
||||
if (requiredBufferSize > this->internalBufferSize) {
|
||||
if (this->sampleSize > this->internalBufferSize) {
|
||||
if (this->buffer) {
|
||||
delete this->buffer;
|
||||
this->buffer = NULL;
|
||||
}
|
||||
|
||||
this->buffer = new float[requiredBufferSize];
|
||||
this->internalBufferSize = requiredBufferSize;
|
||||
this->buffer = new float[this->sampleSize];
|
||||
this->internalBufferSize = this->sampleSize;
|
||||
}
|
||||
}
|
||||
|
||||
/* logical bytes; backing store may be be larger */
|
||||
long Buffer::Bytes() const {
|
||||
return sizeof(float) * this->sampleSize * this->channels;
|
||||
return sizeof(float) * this->sampleSize;
|
||||
}
|
||||
|
||||
double Buffer::Position() const {
|
||||
@ -128,16 +127,16 @@ bool Buffer::Append(BufferPtr appendBuffer) {
|
||||
this->Channels() == appendBuffer->Channels())
|
||||
{
|
||||
/* number of floats (not bytes) in buffer */
|
||||
long newBufferSize = (this->Samples() + appendBuffer->Samples()) * this->channels;
|
||||
long newBufferSize = (this->Samples() + appendBuffer->Samples());
|
||||
|
||||
if (newBufferSize > this->internalBufferSize) { /* resize, then copy, if too small */
|
||||
float *newBuffer = new float[newBufferSize];
|
||||
|
||||
CopyFloat(newBuffer, this->buffer, this->sampleSize * this->channels);
|
||||
CopyFloat(newBuffer, this->buffer, this->sampleSize);
|
||||
|
||||
float *dst = &newBuffer[this->sampleSize * this->channels];
|
||||
float *dst = &newBuffer[this->sampleSize];
|
||||
float *src = appendBuffer->BufferPointer();
|
||||
long count = appendBuffer->Samples() * this->channels;
|
||||
long count = appendBuffer->Samples();
|
||||
|
||||
CopyFloat(dst, src, count);
|
||||
|
||||
@ -151,9 +150,9 @@ bool Buffer::Append(BufferPtr appendBuffer) {
|
||||
this->internalBufferSize = newBufferSize;
|
||||
}
|
||||
else { /* append, no resize required */
|
||||
float *dst = &this->buffer[this->sampleSize * this->channels];
|
||||
float *dst = &this->buffer[this->sampleSize];
|
||||
float *src = appendBuffer->BufferPointer();
|
||||
long count = appendBuffer->Samples() * this->channels;
|
||||
long count = appendBuffer->Samples();
|
||||
CopyFloat(dst, src, count);
|
||||
|
||||
#if DEBUG > 0
|
||||
@ -161,7 +160,7 @@ bool Buffer::Append(BufferPtr appendBuffer) {
|
||||
#endif
|
||||
}
|
||||
|
||||
this->sampleSize = newBufferSize / this->channels;
|
||||
this->sampleSize = newBufferSize;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -300,6 +300,7 @@ bool Player::Exited() {
|
||||
void Player::OnBufferProcessed(IBuffer *buffer) {
|
||||
bool started = false;
|
||||
bool found = false;
|
||||
|
||||
{
|
||||
boost::mutex::scoped_lock lock(this->queueMutex);
|
||||
|
||||
@ -314,17 +315,18 @@ void Player::OnBufferProcessed(IBuffer *buffer) {
|
||||
this->stream->OnBufferProcessedByPlayer(*it);
|
||||
}
|
||||
|
||||
bool isFront = this->lockedBuffers.front() == *it;
|
||||
it = this->lockedBuffers.erase(it);
|
||||
|
||||
/* this sets the current time in the stream. it does this by grabbing
|
||||
the time at the next buffer in the queue */
|
||||
if (!this->lockedBuffers.empty()) {
|
||||
this->currentPosition = this->lockedBuffers.front()->Position();
|
||||
if (this->lockedBuffers.empty() || isFront) {
|
||||
this->currentPosition = ((Buffer*)buffer)->Position();
|
||||
}
|
||||
else {
|
||||
/* if the queue is drained, use the position from the buffer
|
||||
that was just processed */
|
||||
this->currentPosition = ((Buffer*) buffer)->Position();
|
||||
this->currentPosition = this->lockedBuffers.front()->Position();
|
||||
}
|
||||
|
||||
/* if the output device's internal buffers are full, it will stop
|
||||
|
@ -147,7 +147,8 @@ BufferPtr Stream::GetNextBufferFromDecoder() {
|
||||
|
||||
/* calculate the position (seconds) in the buffer */
|
||||
buffer->SetPosition(
|
||||
((double) this->decoderSamplePosition) /
|
||||
((double) this->decoderSamplePosition) /
|
||||
((double) buffer->Channels()) /
|
||||
((double) this->decoderSampleRate));
|
||||
|
||||
return buffer;
|
||||
|
@ -60,7 +60,7 @@ using namespace boost::chrono;
|
||||
using namespace cursespp;
|
||||
|
||||
#define REFRESH_TRANSPORT_READOUT 1001
|
||||
#define REFRESH_INTERVAL_MS 1000
|
||||
#define REFRESH_INTERVAL_MS 500
|
||||
|
||||
#define DEBOUNCE_REFRESH(x) \
|
||||
this->RemoveMessage(REFRESH_TRANSPORT_READOUT); \
|
||||
|
Loading…
Reference in New Issue
Block a user