Starting the Processing Loop - Fail

edited March 2013

Hello Amazing Audio Engine Team,

first of all I wanted to thank you loads for developing this great framework - it should make things soooo much easier!

However, I have a little trouble getting the train rolling.
I'm essentially trying to produce a simple oscillator inspired by your example code. Now, everything seems to be fine and the code compiles, but the actual audio processing loop does not seem to run at all. I tried to print something to the terminal during each iteration of the processing loop. This worked perfectly fine for the included examples, but not at all for my own code. My processing loop just is not getting executed.
Now, could you maybe give me a checklist of things to do in order to get a processing loop running?

Many thanks and all the best,
Simon-Claudius

Comments

  • Cheers, Simon-Claudius =)

    Rather than my trying to guess what could be going wrong, how about you post your code here?

  • edited March 2013
    //
    //  SCWAppDelegate.h
    //  Prototype-1
    //
    //  Created by Simon-Claudius Wystrach on 29/03/2013.
    //  Copyright (c) 2013 Simon-Claudius Wystrach. All rights reserved.
    //
    
    #import 
    
    @class SCWViewController;
    @class AEAudioController;
    
    @interface SCWAppDelegate : UIResponder 
    
    @property (strong, nonatomic) UIWindow *window;
    
    @property (strong, nonatomic) SCWViewController *viewController;
    
    @property (strong, nonatomic) AEAudioController *audioController;
    
    
    
    
    @end
    
  • edited March 2013
    //
    //  SCWAppDelegate.m
    //  Prototype-1
    //
    //  Created by Simon-Claudius Wystrach on 29/03/2013.
    //  Copyright (c) 2013 Simon-Claudius Wystrach. All rights reserved.
    //
    
    #import "SCWAppDelegate.h"
    
    #import "SCWViewController.h"
    #import "TheAmazingAudioEngine.h"
    
    @implementation SCWAppDelegate
    
    @synthesize audioController = _audioController;
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        
        
        // Create an instance of the audio controller, set it up and start it running
        self.audioController = [[AEAudioController alloc]
                                initWithAudioDescription:[AEAudioController nonInterleaved16BitStereoAudioDescription]
                                inputEnabled:YES];
        _audioController.preferredBufferDuration = 0.005;
        [_audioController start:NULL];
    
        
        
        // Override point for customization after application launch.
        self.viewController = [[SCWViewController alloc] initWithNibName:@SCWViewController bundle:nil];
        self.window.rootViewController = self.viewController;
        [self.window makeKeyAndVisible];
        return YES;
    }
    
    - (void)applicationWillResignActive:(UIApplication *)application
    {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
    }
    
    - (void)applicationDidEnterBackground:(UIApplication *)application
    {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }
    
    - (void)applicationWillEnterForeground:(UIApplication *)application
    {
        // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
    }
    
    - (void)applicationDidBecomeActive:(UIApplication *)application
    {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }
    
    - (void)applicationWillTerminate:(UIApplication *)application
    {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }
    
    
    
    @end
    
    
  • edited March 2013
    //
    //  SCWViewController.h
    //  Prototype-1
    //
    //  Created by Simon-Claudius Wystrach on 29/03/2013.
    //  Copyright (c) 2013 Simon-Claudius Wystrach. All rights reserved.
    //
    
    #import 
    #import "TheAmazingAudioEngine.h"
    @class AEAudioController;
    
    
    @interface SCWViewController : UIViewController
    
    
    - (id)initWithAudioController:(AEAudioController*)audioController;
    
    - (IBAction)oscillatorSwitchChanged:(UISwitch *)sender;
    
    @end
    
    
  • edited March 2013
    //
    //  SCWViewController.m
    //  Prototype-1
    //
    //  Created by Simon-Claudius Wystrach on 29/03/2013.
    //  Copyright (c) 2013 Simon-Claudius Wystrach. All rights reserved.
    //
    
    #import "SCWViewController.h"
    #import "AEAudioController.h"
    
    
    
    @interface SCWViewController ()
    @property (nonatomic, retain) AEAudioController *audioController;
    @property (nonatomic, retain) AEBlockChannel *oscillator;
    
    
    
    @end
    
    @implementation SCWViewController
    
    
    
    - (id)initWithAudioController:(AEAudioController*)audioController{
        
            self.audioController = audioController;
        
        
        // Create a block-based channel, with an implementation of an oscillator
        __block float oscillatorPosition = 0;
        __block float oscillatorRate = 622.0/44100.0;
        self.oscillator = [AEBlockChannel channelWithBlock:^(const AudioTimeStamp  *time,
                                                             UInt32           frames,
                                                             AudioBufferList *audio) {
            for ( int i=0; i 1.0 ) oscillatorPosition -= 2.0;
                
                ((SInt16*)audio->mBuffers[0].mData)[i] = x;
                ((SInt16*)audio->mBuffers[1].mData)[i] = x;
                NSLog(@Test);
                
            }
    
        }];
        
         _oscillator.channelIsMuted = YES;
        
        // Add this channel
        [_audioController addChannels:[NSArray arrayWithObjects: _oscillator, nil]];
        
        return self;
    }
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        
    }
    
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    - (IBAction)oscillatorSwitchChanged:(UISwitch *)sender {
            _oscillator.channelIsMuted = !sender.isOn;
        NSLog(@Test);
    }
    
    
    
    @end
    
    
  • edited March 2013

    There you go :)!
    I'm pretty new to Objective-C, so please forgive me if my code is a bit "naive" at this stage.

  • Right, you're using the wrong initializer, so initWithAudioController's never being called.

  • Where should I call it? Sorry... I can't find it in your sample application (at least not for the oscillator example).

  • edited March 2013

    Right, I got it. The processing loop is running now. Here is the code:

    However, I still don't hear any audio output. What else do I have to do?

    Edit: Forget about it, it works now! Thanks so much for your help. I might have more questions along the way. I don't want to bother you too much, but can I also post them here?

    //
    //  SCWAppDelegate.m
    //  Prototype-1
    //
    //  Created by Simon-Claudius Wystrach on 29/03/2013.
    //  Copyright (c) 2013 Simon-Claudius Wystrach. All rights reserved.
    //
    
    #import "SCWAppDelegate.h"
    
    #import "SCWViewController.h"
    #import "TheAmazingAudioEngine.h"
    
    @implementation SCWAppDelegate
    
    @synthesize audioController = _audioController;
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        
        
        // Create an instance of the audio controller, set it up and start it running
        self.audioController = [[AEAudioController alloc]
                                initWithAudioDescription:[AEAudioController nonInterleaved16BitStereoAudioDescription]
                                inputEnabled:YES];
        _audioController.preferredBufferDuration = 0.005;
        [_audioController start:NULL];
    
        
        
        // Override point for customization after application launch.
        self.viewController = [[SCWViewController alloc] initWithNibName:@SCWViewController bundle:nil];
        self.viewController = [[SCWViewController alloc] initWithAudioController:_audioController];
        self.window.rootViewController = self.viewController;
        [self.window makeKeyAndVisible];
        return YES;
    }
    
    - (void)applicationWillResignActive:(UIApplication *)application
    {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
    }
    
    - (void)applicationDidEnterBackground:(UIApplication *)application
    {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }
    
    - (void)applicationWillEnterForeground:(UIApplication *)application
    {
        // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
    }
    
    - (void)applicationDidBecomeActive:(UIApplication *)application
    {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }
    
    - (void)applicationWillTerminate:(UIApplication *)application
    {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }
    
    
    
    @end
    
Sign In or Register to comment.