Comments (2)
Some sample code to trigger the error:
In the calling code add this
#import "ALSamplePlayer.h"
@property (nonatomic, retain) ALSamplePlayer *samplePlayer;
_samplePlayer = [[ALSamplePlayer alloc] initWithAudioController:_audioController];
if (YES) [_samplePlayer schedulePlaybackWithSecondsFromNow:2.0]; // Gives the -10863 error, could it be because of AudioTimeStamp is out of date 'then'?
else [_samplePlayer play]; // Works
ALSamplePlayer.h
#import <Foundation/Foundation.h>
#import "TheAmazingAudioEngine.h"
@interface ALSamplePlayer : NSObject
- (id)initWithAudioController:(AEAudioController*) audioController;
- (void)schedulePlaybackWithSecondsFromNow:(NSTimeInterval)seconds;
- (void)play;
@end
ALSamplePlayer.m
#import "ALSamplePlayer.h"
#define checkResult(result,operation) (_checkResult((result),(operation),strrchr(__FILE__, '/')+1,__LINE__))
static inline BOOL _checkResult(OSStatus result, const char *operation, const char* file, int line) {
if ( result != noErr ) {
int fourCC = CFSwapInt32HostToBig(result);
NSLog(@"%s:%d: %s result %d %08X %4.4s\n", file, line, operation, (int)result, (int)result, (char*)&fourCC);
return NO;
}
return YES;
}
@interface ALSamplePlayer () {
AudioFileID _audioUnitFile;
}
@property (nonatomic, retain) AEBlockScheduler *scheduler;
@property (nonatomic, retain) AEAudioUnitChannel *audioUnitPlayer;
@property (nonatomic, retain) AEAudioController *audioController;
@end
@implementation ALSamplePlayer
- (id)initWithAudioController:(AEAudioController*) audioController {
if (self = [super init]) {
_audioController = audioController;
[self setupPlayer];
[self setupScheduler];
}
return self;
}
- (void)setupPlayer{
// Create an audio unit channel (a file player)
self.audioUnitPlayer = [[[AEAudioUnitChannel alloc] initWithComponentDescription:AEAudioComponentDescriptionMake(kAudioUnitManufacturer_Apple, kAudioUnitType_Generator, kAudioUnitSubType_AudioFilePlayer)
audioController:_audioController
error:NULL] autorelease];
[_audioController addChannels:[NSArray arrayWithObjects:_audioUnitPlayer, nil]];
}
- (void)setupScheduler{
self.scheduler = [[AEBlockScheduler alloc] initWithAudioController:_audioController];
[_audioController addTimingReceiver:_scheduler];
}
- (void)schedulePlaybackWithSecondsFromNow:(NSTimeInterval)seconds{
[self.scheduler scheduleBlock:^(const AudioTimeStamp *intervalStartTime, UInt32 offsetInFrames) {
[self.audioController addChannels:[NSArray arrayWithObject:self.audioUnitPlayer]];
NSLog(@"schedulePlayback triggered");
} atTime:[AEBlockScheduler timestampWithSecondsFromNow:seconds] timingContext:AEAudioTimingContextOutput identifier:@"test"];
}
- (void)play {
if ( !_audioUnitFile ) {
NSURL *playerFile = [[NSBundle mainBundle] URLForResource:@"Southern Rock Drums" withExtension:@"m4a"];
checkResult(AudioFileOpenURL((CFURLRef)playerFile, kAudioFileReadPermission, 0, &_audioUnitFile), "AudioFileOpenURL");
}
// Set the file to play
checkResult(AudioUnitSetProperty(_audioUnitPlayer.audioUnit, kAudioUnitProperty_ScheduledFileIDs, kAudioUnitScope_Global, 0, &_audioUnitFile, sizeof(_audioUnitFile)),
"AudioUnitSetProperty(kAudioUnitProperty_ScheduledFileIDs)");
// Determine file properties
UInt64 packetCount;
UInt32 size = sizeof(packetCount);
checkResult(AudioFileGetProperty(_audioUnitFile, kAudioFilePropertyAudioDataPacketCount, &size, &packetCount),
"AudioFileGetProperty(kAudioFilePropertyAudioDataPacketCount)");
AudioStreamBasicDescription dataFormat;
size = sizeof(dataFormat);
checkResult(AudioFileGetProperty(_audioUnitFile, kAudioFilePropertyDataFormat, &size, &dataFormat),
"AudioFileGetProperty(kAudioFilePropertyDataFormat)");
// Assign the region to play
ScheduledAudioFileRegion region;
memset (®ion.mTimeStamp, 0, sizeof(region.mTimeStamp));
region.mTimeStamp.mFlags = kAudioTimeStampSampleTimeValid;
region.mTimeStamp.mSampleTime = 0;
region.mCompletionProc = NULL;
region.mCompletionProcUserData = NULL;
region.mAudioFile = _audioUnitFile;
region.mLoopCount = 0;
region.mStartFrame = 0;
region.mFramesToPlay = packetCount * dataFormat.mFramesPerPacket;
checkResult(AudioUnitSetProperty(_audioUnitPlayer.audioUnit, kAudioUnitProperty_ScheduledFileRegion, kAudioUnitScope_Global, 0, ®ion, sizeof(region)),
"AudioUnitSetProperty(kAudioUnitProperty_ScheduledFileRegion)");
// Prime the player by reading some frames from disk
UInt32 defaultNumberOfFrames = 0;
checkResult(AudioUnitSetProperty(_audioUnitPlayer.audioUnit, kAudioUnitProperty_ScheduledFilePrime, kAudioUnitScope_Global, 0, &defaultNumberOfFrames, sizeof(defaultNumberOfFrames)),
"AudioUnitSetProperty(kAudioUnitProperty_ScheduledFilePrime)");
// Set the start time (now = -1)
AudioTimeStamp startTime;
memset (&startTime, 0, sizeof(startTime));
startTime.mFlags = kAudioTimeStampSampleTimeValid;
startTime.mSampleTime = -1;
checkResult(AudioUnitSetProperty(_audioUnitPlayer.audioUnit, kAudioUnitProperty_ScheduleStartTimeStamp, kAudioUnitScope_Global, 0, &startTime, sizeof(startTime)),
"AudioUnitSetProperty(kAudioUnitProperty_ScheduleStartTimeStamp)");
}
@end
from theamazingaudioengine.
Actually, this isn't a bug. You can't (a) call objective-C from the schedule block as it's running on the realtime thread, or (b) manipulate the audio graph like that from the realtime thread. That's why you're getting -10863 (or 'kAudioUnitErr_CannotDoInCurrentContext')
from theamazingaudioengine.
Related Issues (20)
- 1.5.7 not on Cocoapods HOT 2
- Open the dome,Bluetooth speakers will automatically stop working? HOT 1
- How can I set the preferredInput? Everytime I change it, it sets it back to previous.
- Stop doesn't work if the audioDescription preferred sampleRate is different than detected
- user AEAudioController Empty my control center
- Using play through channel ,but need to delay the playing
- Prepare and begin recording
- Is TheAmazingAudioEngine possible to perform audio synthesis?
- Can only record m4a type ? HOT 1
- 请问一下theamazingaudioengine 录音的时候如何过滤扬声器声音 HOT 2
- Hi, I need to create a visualizer like ZLHistogramAudioPlot. I try to use this code
- Create ZLHistogramAudioPlot like visualizer using TheAmazingAudioEngine
- React Native version?
- regionStartTime not work
- 可以绘制音波图吗
- Crash AEUtilities.h -[AEAudioController teardown] HOT 1
- demo 不清楚怎么使用的 可以讲一下吗
- Multiple samples not playing at the same time in iOS 14 HOT 5
- `AEAudioBufferListGetLength ()` has a incorrect implementation HOT 2
- How to export modified audio file?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from theamazingaudioengine.