mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-25 16:31:42 +00:00
Fix stereo buffering, various audio asserts.
This commit is contained in:
parent
f465fe65f4
commit
60f997a52c
@ -30,6 +30,8 @@
|
||||
atomic_int _enqueuedBuffers;
|
||||
AudioQueueBufferRef _buffers[NumBuffers];
|
||||
int _bufferWritePointer;
|
||||
|
||||
unsigned int _numChannels;
|
||||
}
|
||||
|
||||
#pragma mark - Status
|
||||
@ -49,6 +51,7 @@
|
||||
atomic_store_explicit(&_enqueuedBuffers, 0, memory_order_relaxed);
|
||||
|
||||
_samplingRate = samplingRate;
|
||||
_numChannels = isStereo ? 2 : 1;
|
||||
|
||||
// Determine preferred buffer size as being the first power of two
|
||||
// not less than 1/100th of a second.
|
||||
@ -138,20 +141,20 @@
|
||||
|
||||
// Allocate future audio buffers.
|
||||
[_queueLock lock];
|
||||
const size_t bufferBytes = self.bufferSize * sizeof(int16_t);
|
||||
const size_t bufferBytes = self.bufferSize * sizeof(int16_t) * _numChannels;
|
||||
for(size_t c = 0; c < NumBuffers; c++) {
|
||||
if(_buffers[c]) {
|
||||
OSSGuard(AudioQueueFreeBuffer(_audioQueue, _buffers[c]));
|
||||
}
|
||||
|
||||
OSSGuard(AudioQueueAllocateBuffer(_audioQueue, (UInt32)bufferBytes * 2, &_buffers[c]));
|
||||
OSSGuard(AudioQueueAllocateBuffer(_audioQueue, (UInt32)bufferBytes, &_buffers[c]));
|
||||
_buffers[c]->mAudioDataByteSize = (UInt32)bufferBytes;
|
||||
}
|
||||
[_queueLock unlock];
|
||||
}
|
||||
|
||||
- (void)enqueueAudioBuffer:(const int16_t *)buffer {
|
||||
const size_t bufferBytes = self.bufferSize * sizeof(int16_t);
|
||||
const size_t bufferBytes = self.bufferSize * sizeof(int16_t) * _numChannels;
|
||||
|
||||
// Don't enqueue more than the allowed number of future buffers,
|
||||
// to ensure not too much latency accrues.
|
||||
|
@ -176,7 +176,7 @@ struct ActivityObserver: public Activity::Observer {
|
||||
}
|
||||
|
||||
- (void)speaker:(Outputs::Speaker::Speaker *)speaker didCompleteSamples:(const int16_t *)samples length:(int)length {
|
||||
assert(NSUInteger(length) == self.audioQueue.bufferSize);
|
||||
assert(NSUInteger(length) == self.audioQueue.bufferSize*(speaker->get_is_stereo() ? 2 : 1));
|
||||
[self.audioQueue enqueueAudioBuffer:samples];
|
||||
}
|
||||
|
||||
|
@ -239,9 +239,9 @@ template <typename ConcreteT, bool is_stereo> class LowpassBase: public Speaker
|
||||
}
|
||||
|
||||
protected:
|
||||
void process(size_t length) {
|
||||
bool process(size_t length) {
|
||||
const auto delegate = delegate_.load(std::memory_order::memory_order_relaxed);
|
||||
if(!delegate) return;
|
||||
if(!delegate) return false;
|
||||
|
||||
const int scale = static_cast<ConcreteT *>(this)->get_scale();
|
||||
|
||||
@ -286,6 +286,8 @@ template <typename ConcreteT, bool is_stereo> class LowpassBase: public Speaker
|
||||
// TODO: input rate is less than output rate.
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
@ -334,8 +336,11 @@ template <bool is_stereo> class PushLowpass: public LowpassBase<PushLowpass<is_s
|
||||
*/
|
||||
void push(const int16_t *buffer, size_t length) {
|
||||
buffer_ = buffer;
|
||||
process(length);
|
||||
assert(buffer_ == buffer + (length * (1 + is_stereo)));
|
||||
#ifndef NDEBUG
|
||||
const bool did_process =
|
||||
#endif
|
||||
process(length);
|
||||
assert(!did_process || buffer_ == buffer + (length * (1 + is_stereo)));
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user