Rewrite attempt number two. Now using array lists of audio chunks, with each chunk having its format and optionally losslessness stashed along with it. This replaces the old virtual ring buffer method. As a result of this, the HRIR toggle now works instantaneously. Signed-off-by: Christopher Snowhill <kode54@gmail.com>
74 lines
1.7 KiB
Objective-C
74 lines
1.7 KiB
Objective-C
//
|
|
// AudioChunk.m
|
|
// CogAudio Framework
|
|
//
|
|
// Created by Christopher Snowhill on 2/5/22.
|
|
//
|
|
|
|
#import "AudioChunk.h"
|
|
|
|
@implementation AudioChunk
|
|
|
|
- (id) init {
|
|
self = [super init];
|
|
|
|
if (self) {
|
|
chunkData = [[NSMutableData alloc] init];
|
|
formatAssigned = NO;
|
|
lossless = NO;
|
|
}
|
|
|
|
return self;
|
|
}
|
|
|
|
@synthesize lossless;
|
|
|
|
- (AudioStreamBasicDescription) format {
|
|
return format;
|
|
}
|
|
|
|
- (void) setFormat:(AudioStreamBasicDescription)informat {
|
|
formatAssigned = YES;
|
|
format = informat;
|
|
}
|
|
|
|
- (void) assignSamples:(const void *)data frameCount:(size_t)count {
|
|
if (formatAssigned) {
|
|
const size_t bytesPerPacket = format.mBytesPerPacket;
|
|
[chunkData appendBytes:data length:bytesPerPacket * count];
|
|
}
|
|
}
|
|
|
|
- (NSData *) removeSamples:(size_t)frameCount {
|
|
if (formatAssigned) {
|
|
const size_t bytesPerPacket = format.mBytesPerPacket;
|
|
const size_t byteCount = bytesPerPacket * frameCount;
|
|
NSData * ret = [chunkData subdataWithRange:NSMakeRange(0, byteCount)];
|
|
[chunkData replaceBytesInRange:NSMakeRange(0, byteCount) withBytes:NULL length:0];
|
|
return ret;
|
|
}
|
|
return [NSData data];
|
|
}
|
|
|
|
- (BOOL) isEmpty {
|
|
return [chunkData length] == 0;
|
|
}
|
|
|
|
- (size_t) frameCount {
|
|
if (formatAssigned) {
|
|
const size_t bytesPerPacket = format.mBytesPerPacket;
|
|
return [chunkData length] / bytesPerPacket;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
- (double) duration {
|
|
if (formatAssigned) {
|
|
const size_t bytesPerPacket = format.mBytesPerPacket;
|
|
const double sampleRate = format.mSampleRate;
|
|
return (double)([chunkData length] / bytesPerPacket) / sampleRate;
|
|
}
|
|
return 0.0;
|
|
}
|
|
|
|
@end
|