MusicKit
0.0.0
|
SndStreamManager abstracts the playing of streams of audio. Provides streaming client connection and stream mixing services, and acts as an abstraction of the sound playing hardware. More...
#import <SndStreamManager.h>
Inherits <SndDelegateMessagePassing>, and <SndDelegateMessagePassing>.
Public Member Functions | |
(id) | - init |
Initialise a SndStreamManager instance on the default input and output devices. | |
(id) | - initOnDeviceForInput:deviceForOutput: |
Initialise a SndStreamManager instance on the named input and output devices. | |
(int) | - assignedDriverIndexForOutput: |
Returns the index into the NSArray returned by +driverNamesForOutput: for the current driver. | |
(BOOL) | - setAssignedDriverToIndex:forOutput: |
Assigns the sound hardware to be the driver referenced by the driver index number. | |
(NSString *) | - assignedDriverNameForOutput: |
Returns an NSString of the current driver. | |
(BOOL) | - setHardwareBufferSize: |
Sets the number of sample frames used by the audio input and output hardware. | |
(long) | - inputBufferSize |
Returns the number of sample frames currently used by the audio input hardware. | |
(long) | - outputBufferSize |
Returns the number of sample frames currently used by the audio output hardware. | |
(float) | - inputLatency |
Returns an estimate of the number of seconds of latency between the hardware recording audio and when it will first be processed by this class's processStreamAtTime: method. | |
(float) | - outputLatency |
Returns an estimate of the number of seconds of latency between when an audio buffer will be dispatched to be output by this class's processStreamAtTime: method and when the hardware will play it. | |
(NSString *) | - description |
Returns an NSString with description of SndStreamManager. | |
(void) | - startStreaming |
Starts streaming. | |
(void) | - stopStreaming |
Stops streaming. | |
(BOOL) | - addClient: |
Adds an SndStreamClient to the manager's mixer. | |
(BOOL) | - removeClient: |
Removes the SndStreamClient from the manager's mixer. | |
(BOOL) | - removeAllClients |
Removes all the SndStreamClients from the manager's mixer. | |
(NSArray *) | - clients |
Returns an NSArray of clients of the SndStreamManager instance. | |
(void) | - processStreamAtTime:input:output: |
Passes new input and output buffers from the underlying API to the mixer. | |
(SndFormat) | - format |
Returns the output format to be used during streaming. | |
(double) | - nowTime |
Return the current time as understood by the SndStreamManager. | |
(SndStreamMixer *) | - mixer |
Mixer member accessor method. | |
(BOOL) | - isActive |
indicates whether streaming is happening (active) | |
(double) | - samplingRate |
(void) | - resetTime: |
Resets the global stream time to originTimeInSeconds. | |
(void) | - sendMessageInMainThreadToTarget:sel:arg1:arg2: |
Sends messages from any thread to any object in the main thread. | |
(id) | - init |
Initialise a SndStreamManager instance on the default input and output devices. | |
(id) | - initOnDeviceForInput:deviceForOutput: |
Initialise a SndStreamManager instance on the named input and output devices. | |
(int) | - assignedDriverIndexForOutput: |
Returns the index into the NSArray returned by +driverNamesForOutput: for the current driver. | |
(BOOL) | - setAssignedDriverToIndex:forOutput: |
Assigns the sound hardware to be the driver referenced by the driver index number. | |
(NSString *) | - assignedDriverNameForOutput: |
Returns an NSString of the current driver. | |
(BOOL) | - setHardwareBufferSize: |
Sets the number of sample frames used by the audio input and output hardware. | |
(long) | - inputBufferSize |
Returns the number of sample frames currently used by the audio input hardware. | |
(long) | - outputBufferSize |
Returns the number of sample frames currently used by the audio output hardware. | |
(float) | - inputLatency |
Returns an estimate of the number of seconds of latency between the hardware recording audio and when it will first be processed by this class's processStreamAtTime: method. | |
(float) | - outputLatency |
Returns an estimate of the number of seconds of latency between when an audio buffer will be dispatched to be output by this class's processStreamAtTime: method and when the hardware will play it. | |
(NSString *) | - description |
Returns an NSString with description of SndStreamManager. | |
(void) | - startStreaming |
Starts streaming. | |
(void) | - stopStreaming |
Stops streaming. | |
(BOOL) | - addClient: |
Adds an SndStreamClient to the manager's mixer. | |
(BOOL) | - removeClient: |
Removes the SndStreamClient from the manager's mixer. | |
(BOOL) | - removeAllClients |
Removes all the SndStreamClients from the manager's mixer. | |
(NSArray *) | - clients |
Returns an NSArray of clients of the SndStreamManager instance. | |
(void) | - processStreamAtTime:input:output: |
Passes new input and output buffers from the underlying API to the mixer. | |
(SndFormat) | - format |
Returns the output format to be used during streaming. | |
(double) | - nowTime |
Return the current time as understood by the SndStreamManager. | |
(SndStreamMixer *) | - mixer |
Mixer member accessor method. | |
(BOOL) | - isActive |
indicates whether streaming is happening (active) | |
(double) | - samplingRate |
(void) | - resetTime: |
Resets the global stream time to originTimeInSeconds. | |
(void) | - sendMessageInMainThreadToTarget:sel:arg1:arg2: |
Sends messages from any thread to any object in the main thread. | |
Static Public Member Functions | |
(void) | + initialize |
Class initialization method. | |
(SndStreamManager *) | + defaultStreamManager |
Accessor to the default stream manager created upon class initialization. | |
(id) | + streamManagerOnDeviceForInput:deviceForOutput: |
Creates and returns an autoreleased instance with the specified devices for output and input. | |
(NSArray *) | + driverNamesForOutput: |
Returns an NSArray of NSStrings listing the sound drivers available. | |
(void) | + initialize |
Class initialization method. | |
(SndStreamManager *) | + defaultStreamManager |
Accessor to the default stream manager created upon class initialization. | |
(id) | + streamManagerOnDeviceForInput:deviceForOutput: |
Creates and returns an autoreleased instance with the specified devices for output and input. | |
(NSArray *) | + driverNamesForOutput: |
Returns an NSArray of NSStrings listing the sound drivers available. | |
Protected Attributes | |
SndStreamMixer * | mixer |
BOOL | active |
BOOL | bg_active |
SndFormat | outputFormat |
SndFormat | inputFormat |
double | nowTime |
char | bg_sem |
char | bgdm_sem |
NSConditionLock * | bg_threadLock |
NSConditionLock * | bgdm_threadLock |
BOOL | isStopping |
SndStreamManager abstracts the playing of streams of audio. Provides streaming client connection and stream mixing services, and acts as an abstraction of the sound playing hardware.
In practice, the hardware is further abstracted by a platform specific interface that encapsulated by the lowlevel MKPerformSndMIDI C functions.
Each SndStreamManager has a SndStreamMixer which has a SndAudioProcessorChain which has a SndAudioFader. Adding clients to a manager adds them to the underlying mixer.
- (BOOL) addClient: | (SndStreamClient *) | client |
Adds an SndStreamClient to the manager's mixer.
If the SndStreamClient is already a client of the mixer, it is NOT added again. If the client is the first connected to the manager, the manager will automatically start streaming.
client | The SndStreamClient instance to begin managing and mixing. |
- (BOOL) addClient: | (SndStreamClient *) | client |
Adds an SndStreamClient to the manager's mixer.
If the SndStreamClient is already a client of the mixer, it is NOT added again. If the client is the first connected to the manager, the manager will automatically start streaming.
client | The SndStreamClient instance to begin managing and mixing. |
- (int) assignedDriverIndexForOutput: | (BOOL) | forOutputDevices |
Returns the index into the NSArray returned by +driverNamesForOutput: for the current driver.
forOutputDevices | YES to retrieve the assigned output device number, NO to retrieve the assigned input device number. |
- (int) assignedDriverIndexForOutput: | (BOOL) | forOutputDevices |
Returns the index into the NSArray returned by +driverNamesForOutput: for the current driver.
forOutputDevices | YES to retrieve the assigned output device number, NO to retrieve the assigned input device number. |
- (NSString *) assignedDriverNameForOutput: | (BOOL) | forOutputDevices |
Returns an NSString of the current driver.
forOutputDevices | YES to retrieve the assigned output device name, NO to retrieve the assigned input device name. |
- (NSString *) assignedDriverNameForOutput: | (BOOL) | forOutputDevices |
Returns an NSString of the current driver.
forOutputDevices | YES to retrieve the assigned output device name, NO to retrieve the assigned input device name. |
- (NSArray *) clients |
Returns an NSArray of clients of the SndStreamManager instance.
- (NSArray *) clients |
Returns an NSArray of clients of the SndStreamManager instance.
Accessor to the default stream manager created upon class initialization.
SndStreamClients will usually connect to the default stream manager, unless the user wishes to explicitly create their own manager.
Accessor to the default stream manager created upon class initialization.
SndStreamClients will usually connect to the default stream manager, unless the user wishes to explicitly create their own manager.
- (NSString *) description |
Returns an NSString with description of SndStreamManager.
- (NSString *) description |
Returns an NSString with description of SndStreamManager.
+ (NSArray *) driverNamesForOutput: | (BOOL) | forOutputDevices |
Returns an NSArray of NSStrings listing the sound drivers available.
forOutputDevices | YES to retrieve only the output devices, NO to retrieve only the input devices. The format of the names is dependent on the underlying operating system. |
+ (NSArray *) driverNamesForOutput: | (BOOL) | forOutputDevices |
Returns an NSArray of NSStrings listing the sound drivers available.
forOutputDevices | YES to retrieve only the output devices, NO to retrieve only the input devices. The format of the names is dependent on the underlying operating system. |
Returns the output format to be used during streaming.
Returns the output format to be used during streaming.
- (id) init |
Initialise a SndStreamManager instance on the default input and output devices.
The actual devices chosen are platform dependent.
- (id) init |
Initialise a SndStreamManager instance on the default input and output devices.
The actual devices chosen are platform dependent.
+ (void) initialize |
Class initialization method.
Creates the default stream manager
+ (void) initialize |
Class initialization method.
Creates the default stream manager
- (id) initOnDeviceForInput: | (NSString *) | inputDeviceName | |
deviceForOutput: | (NSString *) | outputDeviceName | |
Initialise a SndStreamManager instance on the named input and output devices.
The input and output device names must match those in the arrays returned by +driverNamesForOutput:.
inputDeviceName | Name of the device to stream audio from. |
outputDeviceName | Name of the device to stream audio to. |
- (id) initOnDeviceForInput: | (NSString *) | inputDeviceName | |
deviceForOutput: | (NSString *) | outputDeviceName | |
Initialise a SndStreamManager instance on the named input and output devices.
The input and output device names must match those in the arrays returned by +driverNamesForOutput:.
inputDeviceName | Name of the device to stream audio from. |
outputDeviceName | Name of the device to stream audio to. |
- (long) inputBufferSize |
Returns the number of sample frames currently used by the audio input hardware.
- (long) inputBufferSize |
Returns the number of sample frames currently used by the audio input hardware.
- (float) inputLatency |
Returns an estimate of the number of seconds of latency between the hardware recording audio and when it will first be processed by this class's processStreamAtTime: method.
Note that SndStreamClients may create their own additional latency, based on the number and size of processing buffers they use.
- (float) inputLatency |
Returns an estimate of the number of seconds of latency between the hardware recording audio and when it will first be processed by this class's processStreamAtTime: method.
Note that SndStreamClients may create their own additional latency, based on the number and size of processing buffers they use.
- (BOOL) isActive |
indicates whether streaming is happening (active)
- (BOOL) isActive |
indicates whether streaming is happening (active)
- (SndStreamMixer *) mixer |
Mixer member accessor method.
- (SndStreamMixer *) mixer |
Mixer member accessor method.
- (double) nowTime |
Return the current time as understood by the SndStreamManager.
The current time indicates the time at the start of the next buffer to be mixed and then played. This is about as close to actual playing time as can be calculated. The actual time of play will depend on the operating system dependent latency between receiving a buffer to play and actually sending it to the DAC.
- (double) nowTime |
Return the current time as understood by the SndStreamManager.
The current time indicates the time at the start of the next buffer to be mixed and then played. This is about as close to actual playing time as can be calculated. The actual time of play will depend on the operating system dependent latency between receiving a buffer to play and actually sending it to the DAC.
- (long) outputBufferSize |
Returns the number of sample frames currently used by the audio output hardware.
- (long) outputBufferSize |
Returns the number of sample frames currently used by the audio output hardware.
- (float) outputLatency |
Returns an estimate of the number of seconds of latency between when an audio buffer will be dispatched to be output by this class's processStreamAtTime: method and when the hardware will play it.
Note that SndStreamClients may create their own additional latency, based on the number and size of processing buffers they use.
- (float) outputLatency |
Returns an estimate of the number of seconds of latency between when an audio buffer will be dispatched to be output by this class's processStreamAtTime: method and when the hardware will play it.
Note that SndStreamClients may create their own additional latency, based on the number and size of processing buffers they use.
- (void) processStreamAtTime: | (double) | bufferTime | |
input: | (SndAudioBuffer *) | inB | |
output: | (SndAudioBuffer *) | outB | |
Passes new input and output buffers from the underlying API to the mixer.
Do not call this method - it is part of the audio callback handler.
bufferTime | Time in seconds when the buffer will play. |
inB | The input buffer holding samples recorded from the ADC. |
outB | The output buffer holding samples to be played. |
- (void) processStreamAtTime: | (double) | bufferTime | |
input: | (SndAudioBuffer *) | inB | |
output: | (SndAudioBuffer *) | outB | |
Passes new input and output buffers from the underlying API to the mixer.
Do not call this method - it is part of the audio callback handler.
bufferTime | Time in seconds when the buffer will play. |
inB | The input buffer holding samples recorded from the ADC. |
outB | The output buffer holding samples to be played. |
- (BOOL) removeAllClients |
Removes all the SndStreamClients from the manager's mixer.
Streaming will be automatically shut down.
- (BOOL) removeAllClients |
Removes all the SndStreamClients from the manager's mixer.
Streaming will be automatically shut down.
- (BOOL) removeClient: | (SndStreamClient *) | client |
Removes the SndStreamClient from the manager's mixer.
If the removed client was the last client connected to the manager, streaming will be automatically shut down.
client | The client to be disconnected from the manager. |
- (BOOL) removeClient: | (SndStreamClient *) | client |
Removes the SndStreamClient from the manager's mixer.
If the removed client was the last client connected to the manager, streaming will be automatically shut down.
client | The client to be disconnected from the manager. |
- (void) resetTime: | (double) | originTimeInSeconds |
Resets the global stream time to originTimeInSeconds.
originTimeInSeconds | New origin time, in seconds. |
The new origin time is propagated to the mixer, and thus to the stream clients.
- (void) resetTime: | (double) | originTimeInSeconds |
Resets the global stream time to originTimeInSeconds.
originTimeInSeconds | New origin time, in seconds. |
The new origin time is propagated to the mixer, and thus to the stream clients.
- (double) samplingRate |
- (double) samplingRate |
- (void) sendMessageInMainThreadToTarget: | (id) | target | |
sel: | (SEL) | sel | |
arg1: | (id) | arg1 | |
arg2: | (id) | arg2 | |
Sends messages from any thread to any object in the main thread.
This method was introduced to allow easy delegate messaging from the underlying audio threads, but can be used by any object. The method creates an NSInvocation out of the parameters given, and adds it to an array of waiting messages. Then a background thread with an NSConnection to the main thread is notified, and the messages are passed up the connection one by one, and dispatched in the main thread. Note that the final dispatch is only done as part of the application's NSRunLoop, which means that if the main thread is busy doing anything, it can tke a little while for the delegate message to appear. Even if this is the case, this method should not block for long.
target | id target object |
sel | SEL the selector to be sent, eg @selector(description:withObject:) |
arg1 | the first argument in the selector |
arg2 | the second argument in the selector |
- (void) sendMessageInMainThreadToTarget: | (id) | target | |
sel: | (SEL) | sel | |
arg1: | (id) | arg1 | |
arg2: | (id) | arg2 | |
Sends messages from any thread to any object in the main thread.
This method was introduced to allow easy delegate messaging from the underlying audio threads, but can be used by any object. The method creates an NSInvocation out of the parameters given, and adds it to an array of waiting messages. Then a background thread with an NSConnection to the main thread is notified, and the messages are passed up the connection one by one, and dispatched in the main thread. Note that the final dispatch is only done as part of the application's NSRunLoop, which means that if the main thread is busy doing anything, it can tke a little while for the delegate message to appear. Even if this is the case, this method should not block for long.
target | id target object |
sel | SEL the selector to be sent, eg @selector(description:withObject:) |
arg1 | the first argument in the selector |
arg2 | the second argument in the selector |
- (BOOL) setAssignedDriverToIndex: | (unsigned int) | driverIndex | |
forOutput: | (BOOL) | forOutputDevices | |
Assigns the sound hardware to be the driver referenced by the driver index number.
driverIndex | Must be a number that corresponds to the list of driver names returned by +driverNamesForOutput: |
forOutputDevices | YES to retrieve the assigned output device number, NO to retrieve the assigned input device number. |
- (BOOL) setAssignedDriverToIndex: | (unsigned int) | driverIndex | |
forOutput: | (BOOL) | forOutputDevices | |
Assigns the sound hardware to be the driver referenced by the driver index number.
driverIndex | Must be a number that corresponds to the list of driver names returned by +driverNamesForOutput: |
forOutputDevices | YES to retrieve the assigned output device number, NO to retrieve the assigned input device number. |
- (BOOL) setHardwareBufferSize: | (unsigned int) | frames |
Sets the number of sample frames used by the audio input and output hardware.
The buffer size refers to the number of samples which are output to the DAC in one write operation and input to the ADC in one read operation. Both input and output buffers are enforced to be the same.
frames | Sets the number of frames (channel independent) in the hardware buffer, if possible. |
- (BOOL) setHardwareBufferSize: | (unsigned int) | frames |
Sets the number of sample frames used by the audio input and output hardware.
The buffer size refers to the number of samples which are output to the DAC in one write operation and input to the ADC in one read operation. Both input and output buffers are enforced to be the same.
frames | Sets the number of frames (channel independent) in the hardware buffer, if possible. |
- (void) startStreaming |
Starts streaming.
You should never need to call this. Streaming is started automatically when the first client connects to the manager.
- (void) startStreaming |
Starts streaming.
You should never need to call this. Streaming is started automatically when the first client connects to the manager.
- (void) stopStreaming |
Stops streaming.
You should never need to call this. Streaming is stopped automatically when the last client disconnects from the manager.
- (void) stopStreaming |
Stops streaming.
You should never need to call this. Streaming is stopped automatically when the last client disconnects from the manager.
+ (id) streamManagerOnDeviceForInput: | (NSString *) | inputDeviceName | |
deviceForOutput: | (NSString *) | outputDeviceName | |
Creates and returns an autoreleased instance with the specified devices for output and input.
The input and output device names must match those in the arrays returned by +driverNamesForOutput:.
inputDeviceName | Name of the device to stream audio from. |
outputDeviceName | Name of the device to stream audio to. |
+ (id) streamManagerOnDeviceForInput: | (NSString *) | inputDeviceName | |
deviceForOutput: | (NSString *) | outputDeviceName | |
Creates and returns an autoreleased instance with the specified devices for output and input.
The input and output device names must match those in the arrays returned by +driverNamesForOutput:.
inputDeviceName | Name of the device to stream audio from. |
outputDeviceName | Name of the device to stream audio to. |
- (BOOL) active [protected] |
active Stores the streaming state of the manager.
- (BOOL) bg_active [protected] |
bg_active Whether or not the backgroup stream stopping/starting thread has been created.
- (char) bg_sem [protected] |
bg_sem Semaphore to the background thread to start/stop streaming.
- (NSConditionLock *) bg_threadLock [protected] |
bg_threadLock used for signalling to background thread to start streaming, stop streaming, or abort itself.
- (char) bgdm_sem [protected] |
bgdm_sem Semaphore to the background delegate messaging thread to notify it of data being ready for it.
- (NSConditionLock *) bgdm_threadLock [protected] |
bgdm_threadLock used for controlling access to back ground delegate messaging code.
- (SndFormat) inputFormat [protected] |
inputFormat SndFormat containing stream format information for input.
- (BOOL) isStopping [protected] |
isStopping Indicates the SndStreamManager is in the process of stopping.
- (SndStreamMixer *) mixer [protected] |
mixer A stream client mixer.
- (double) nowTime [protected] |
nowTime Manager's conception of time, in seconds.
- (SndFormat) outputFormat [protected] |
outputFormat SndFormat containing stream format information for output.