summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxant <xant@dyne.org>2012-12-10 17:19:10 (GMT)
committer xant <xant@dyne.org>2012-12-10 17:19:10 (GMT)
commitbd3524e659e7178ec345d86141edd8dbb9c457e3 (patch)
treeb4e246f326a2ff220c750fb0f43aa183e009966a
parent3860332007c1ce801b08f6107534bbc74df52046 (diff)
simplify implementation and make it work through a passive pin
-rw-r--r--entities/JMXAudioMixer.h11
-rw-r--r--entities/JMXAudioMixer.mm122
2 files changed, 8 insertions, 125 deletions
diff --git a/entities/JMXAudioMixer.h b/entities/JMXAudioMixer.h
index efb8011..36b1788 100644
--- a/entities/JMXAudioMixer.h
+++ b/entities/JMXAudioMixer.h
@@ -21,17 +21,8 @@
JMXInputPin *audioInputPin;
JMXOutputPin *audioOutputPin;
@private
- //JMXAudioBuffer *currentSample;
- uint64_t lastSampleTime;
- JMXAudioBuffer *samples[kJMXAudioMixerSamplesBufferCount];
- UInt32 rOffset;
- UInt32 wOffset;
- JMXAudioDevice *device;
- JMXAudioFormat *format;
- BOOL prefill; // defaults to YES
- BOOL useAggregateDevice; // defaults to YES
}
-@property (readwrite) BOOL useAggregateDevice;
+@property (atomic, readonly) JMXAudioBuffer *outputAudio;
@end
diff --git a/entities/JMXAudioMixer.mm b/entities/JMXAudioMixer.mm
index 7d9a5cc..068a7f4 100644
--- a/entities/JMXAudioMixer.mm
+++ b/entities/JMXAudioMixer.mm
@@ -15,7 +15,7 @@
@implementation JMXAudioMixer
-@synthesize useAggregateDevice;
+@synthesize outputAudio;
- (id)init
{
@@ -23,40 +23,22 @@
if (self) {
audioInputPin = [self registerInputPin:@"audio" withType:kJMXAudioPin];
[audioInputPin allowMultipleConnections:YES];
- audioOutputPin = [self registerOutputPin:@"audio" withType:kJMXAudioPin];
+ audioOutputPin = [self registerOutputPin:@"audio" withType:kJMXAudioPin andSelector:@"outputAudio"];
+ audioOutputPin.mode = kJMXPinModePassive;
[audioOutputPin allowMultipleConnections:YES];
- self.frequency = [NSNumber numberWithDouble:(44100/512)];
- useAggregateDevice = NO;
- prefill = YES;
- format = nil;
- rOffset = wOffset = 0;
- // TODO - if using aggregate device we don't need to be threaded
- JMXThreadedEntity *threadedEntity = [[JMXThreadedEntity threadedEntity:self] retain];
- if (threadedEntity)
- return (JMXAudioMixer *)threadedEntity;
- [self dealloc];
+ //self.frequency = [NSNumber numberWithDouble:(44100/512)*2];
+ return self;
}
return nil;
}
- (void)dealloc
{
- /*
- if (samples)
- [samples release];
- */
- if (device)
- [device release];
[super dealloc];
}
-- (void)tick:(uint64_t)timeStamp
+- (JMXAudioBuffer *)outputAudio
{
-
- if (rOffset < wOffset && !prefill) {
- JMXAudioBuffer *outSample = samples[rOffset++%kJMXAudioMixerSamplesBufferCount];
- [audioOutputPin deliverData:[outSample autorelease] fromSender:self];
- }
NSArray *newSamples = [audioInputPin readProducers];
JMXAudioBuffer *currentSample = nil;
for (JMXAudioBuffer *sample in newSamples) {
@@ -76,97 +58,7 @@
}
}
}
- if (currentSample)
- samples[wOffset++%kJMXAudioMixerSamplesBufferCount] = [currentSample retain];
-
- if ((wOffset - rOffset)%kJMXAudioMixerSamplesBufferCount > 10)
- prefill = NO;
- [super outputDefaultSignals:timeStamp];
-}
-
-- (void)provideSamplesToDevice:(JMXAudioDevice *)device
- timeStamp:(AudioTimeStamp *)timeStamp
- inputData:(AudioBufferList *)inInputData
- inputTime:(AudioTimeStamp *)inInputTime
- outputData:(AudioBufferList *)outOutputData
- outputTime:(AudioTimeStamp *)inOutputTime
- clientData:(JMXAudioMixer *)clientData
-
-{
- if ((wOffset - rOffset)%kJMXAudioMixerSamplesBufferCount > 0) {
- JMXAudioBuffer *sample = nil;
- sample = samples[rOffset++%kJMXAudioMixerSamplesBufferCount];
- if (sample) {
- int i;
- for (i = 0; i < inInputData->mNumberBuffers; i++) {
- SInt32 bytesToCopy = MIN(inInputData->mBuffers[i].mDataByteSize, sample.bufferList->mBuffers[i].mDataByteSize);
- if (inInputData->mBuffers[i].mData && sample.bufferList->mNumberBuffers > i) {
- memcpy(inInputData->mBuffers[i].mData,
- sample.bufferList->mBuffers[i].mData,
- bytesToCopy);
- inInputData->mBuffers[i].mDataByteSize = bytesToCopy;
- inInputData->mBuffers[i].mNumberChannels = sample.bufferList->mBuffers[i].mNumberChannels;
- }
- }
- [sample autorelease];
- }
- }
- [clientData tick:CVGetCurrentHostTime()];
-}
-
-
-- (void)start
-{
- if (self.active)
- return;
-
- if (useAggregateDevice) {
- device = [[JMXAudioDevice aggregateDevice:@"JMXMixer"] retain];
- [device setIOTarget:self
- withSelector:@selector(provideSamplesToDevice:timeStamp:inputData:inputTime:outputData:outputTime:clientData:)
- withClientData:self];
- format = [[device streamDescriptionForChannel:0 forDirection:kJMXAudioInput] retain];
- [self activate];
- [device deviceStart];
- } else { // start the thread only if don't want to use the aggregate device
- [super start];
- }
-}
-
-- (void)stop
-{
- if (!self.active)
- return;
- if (useAggregateDevice) {
- [self deactivate];
- if (device) {
- [device deviceStop];
- [device release];
- device = nil;
- [format release];
- format = nil;
- }
- } else { // start the thread only if don't want to use the aggregate device
- [super stop];
- }
-}
-
-- (BOOL)useAggregateDevice
-{
- @synchronized(self) {
- return useAggregateDevice;
- }
-}
-
-- (void)setUseAggregateDevice:(BOOL)value
-{
- // refulse to change the flag if we are running
- // TODO - we should just stop/restart and allow
- // changing the mode while running
- @synchronized(self) {
- if (!self.active)
- useAggregateDevice = value;
- }
+ return currentSample;
}
@end