mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-15 18:16:44 +02:00
fix
git-svn-id: svn://elaine/murooma/trunk@198 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
parent
90932e45f4
commit
dcfe13dfff
2 changed files with 12 additions and 8 deletions
|
@ -3,15 +3,17 @@
|
|||
#include <iostream>
|
||||
|
||||
|
||||
Chunk::Chunk(size_t hz, size_t channels, size_t bitPerSample, WireChunk* _wireChunk) : wireChunk(_wireChunk), hz_(hz), channels_(channels), bytesPerSample_(bitPerSample/8), frameSize_(bytesPerSample_*channels_), idx(0)
|
||||
Chunk::Chunk(size_t hz, size_t channels, size_t bitPerSample, WireChunk* _wireChunk) : wireChunk(_wireChunk), hz_(hz), channels_(channels), bytesPerSample_(bitPerSample/8), idx(0)
|
||||
{
|
||||
frameSize_ = bytesPerSample_*channels_;
|
||||
}
|
||||
|
||||
|
||||
Chunk::Chunk(size_t hz, size_t channels, size_t bitPerSample, size_t ms) : hz_(hz), channels_(channels), bytesPerSample_(bitPerSample/8), frameSize_(bytesPerSample_*channels_), idx(0)
|
||||
Chunk::Chunk(size_t hz, size_t channels, size_t bitPerSample, size_t ms) : hz_(hz), channels_(channels), bytesPerSample_(bitPerSample/8), idx(0)
|
||||
{
|
||||
frameSize_ = bytesPerSample_*channels_;
|
||||
wireChunk = new WireChunk;
|
||||
wireChunk->length = hz*channels*bytesPerSample_*ms / 1000;
|
||||
wireChunk->length = hz*frameSize_*ms / 1000;
|
||||
wireChunk->payload = (char*)malloc(wireChunk->length);
|
||||
}
|
||||
|
||||
|
@ -33,22 +35,24 @@ bool Chunk::isEndOfChunk() const
|
|||
double Chunk::getDuration() const
|
||||
{
|
||||
// std::cout << "len: " << wireChunk->length << ", channels: " << channels_ << ", bytesPerSample: " << bytesPerSample_ << ", hz: " << hz_ << "\n";
|
||||
return wireChunk->length / (channels_ * bytesPerSample_ * hz_ / 1000.);
|
||||
return wireChunk->length / (frameSize_ * hz_ / 1000.);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int Chunk::read(void* outputBuffer, size_t frameCount)
|
||||
{
|
||||
//std::cout << "read: " << frameCount << std::endl;
|
||||
//std::cout << "read: " << frameCount << ", total: " << (wireChunk->length / frameSize_) << ", idx: " << idx;// << std::endl;
|
||||
int result = frameCount;
|
||||
if (idx + frameCount > wireChunk->length / frameSize_)
|
||||
if (idx + frameCount > (wireChunk->length / frameSize_))
|
||||
result = (wireChunk->length / frameSize_) - idx;
|
||||
|
||||
//std::cout << ", from: " << frameSize_*idx << ", to: " << frameSize_*idx + frameSize_*result;
|
||||
if (outputBuffer != NULL)
|
||||
memcpy(outputBuffer, wireChunk->payload + frameSize_*idx, frameSize_*result);
|
||||
memcpy((char*)outputBuffer, (char*)(wireChunk->payload) + frameSize_*idx, frameSize_*result);
|
||||
|
||||
idx += result;
|
||||
//std::cout << ", new idx: " << idx << ", result: " << result << std::endl;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue