MusicKit  0.0.0
SndAudioBuffer.h
00001 
00002 //
00003 //  $Id$
00004 //
00005 //  Description: An object containing raw audio data, and doing audio 
00006 //               operations on that data
00007 //
00008 //  Original Author: SKoT McDonald, <skot@tomandandy.com>
00009 //
00010 //  Copyright (c) 2001, The MusicKit Project.  All rights reserved.
00011 //
00012 //  Permission is granted to use and modify this code for commercial and 
00013 //  non-commercial purposes so long as the author attribution and copyright 
00014 //  messages remain intact and accompany all relevant code.
00015 //
00017 
00018 #ifndef __SNDAUDIOBUFFER_H__
00019 #define __SNDAUDIOBUFFER_H__
00020 
00021 #import <Foundation/Foundation.h>
00022 #import "Snd.h"
00023 #import "SndFunctions.h"
00024 #import "SndFormat.h"
00025 
00026 // Describes each speakerConfiguration index
00027 typedef enum {
00028     SND_SPEAKER_UNUSED = -1,
00029     SND_SPEAKER_LEFT = 0,
00030     SND_SPEAKER_RIGHT = 1,
00031     SND_SPEAKER_LEFT_SURROUND = 2,
00032     SND_SPEAKER_RIGHT_SURROUND = 3,
00033     SND_SPEAKER_CENTRE = 4, 
00034     SND_SPEAKER_LFE = 5,
00035     SND_SPEAKER_CENTRE_REAR = 6,
00036     // (More To Be Determined)
00037     SND_SPEAKER_SIZE
00038 } SndSpeakerPosition;
00039 
00051 @interface SndAudioBuffer : NSObject
00052 {
00054     SndFormat format;
00056     NSMutableData *data;
00061     signed char *speakerConfiguration;
00062 }
00063 
00072 + audioBufferWithDataFormat: (SndSampleFormat) dataFormat
00073                channelCount: (int) channelCount
00074                samplingRate: (double) sampleRate
00075                    duration: (double) timeInSeconds;
00076 
00085 + audioBufferWithDataFormat: (SndSampleFormat) newDataFormat
00086                channelCount: (int) newChannelCount
00087                samplingRate: (double) newSamplingRate
00088                  frameCount: (long) newFrameCount;
00089 
00095 + audioBufferWithFormat: (SndFormat) format;
00096 
00105 + audioBufferWithFormat: (SndFormat *) format data: (void *) dataPointer;
00106 
00112 + audioBufferWithSNDStreamBuffer: (SNDStreamBuffer *) streamBuffer;
00113 
00120 + audioBufferWithSnd: (Snd *) snd inRange: (NSRange) rangeInFrames;
00121 
00131 - initWithFormat: (SndFormat *) format data: (void *) sampleData;
00132 
00140 - initWithBuffer: (SndAudioBuffer *) sndBuffer;
00141 
00148 - initWithBuffer: (SndAudioBuffer *) sndBuffer
00149            range: (NSRange) rangeInFrames;
00150 
00161 - initWithDataFormat: (SndSampleFormat) dataFormat
00162         channelCount: (int) channelCount
00163         samplingRate: (double) samplingRate
00164           frameCount: (long) newFrameCount;
00165 
00176 - initWithDataFormat: (SndSampleFormat) dataFormat
00177         channelCount: (int) channelCount
00178         samplingRate: (double) samplingRate
00179             duration: (double) timeInSeconds;
00180 
00192 - (long) mixWithBuffer: (SndAudioBuffer *) buff
00193              fromStart: (unsigned long) start
00194                  toEnd: (unsigned long) end
00195              canExpand: (BOOL) expand;
00196 
00204 - (long) mixWithBuffer: (SndAudioBuffer *) buff;
00205 
00210 - (id) copyWithZone: (NSZone *) zone;
00211 
00219 - copyDataFromBuffer: (SndAudioBuffer *) audioBufferToCopyFrom;
00220 
00231 - copyBytes: (void *) bytes count: (unsigned int) count format: (SndFormat) format;
00232 
00243 - copyBytes: (void *) bytes intoRange: (NSRange) range format: (SndFormat) format;
00244 
00253 - copyFromBuffer: (SndAudioBuffer *) sourceBuffer intoRange: (NSRange) rangeInSamples;
00254 
00264 - (long) copyFromBuffer: (SndAudioBuffer *) fromBuffer
00265          intoFrameRange: (NSRange) bufferRange
00266          fromFrameRange: (NSRange) fromFrameRange;
00267 
00274 - (void) fillSNDStreamBuffer: (SNDStreamBuffer *) streamBuffer;
00275 
00284 - (SndAudioBuffer *) audioBufferOfChannel: (int) channel;
00285 
00293 - (unsigned long) lengthInSampleFrames;
00294 
00300 - setLengthInSampleFrames: (unsigned long) newSampleFrameCount;
00301 
00306 - (long) lengthInBytes;
00307 
00312 - (double) duration;
00313 
00318 - (double) samplingRate;
00319 
00324 - (int) channelCount;
00325 
00330 - (SndSampleFormat) dataFormat;
00331 
00336 - (SndFormat) format;
00337 
00344 - (void *) bytes;
00345 
00354 - (BOOL) hasSameFormatAsBuffer: (SndAudioBuffer*) buff;
00355 
00360 - zero;
00361 
00368 - zeroFrameRange: (NSRange) frameRange;
00369  
00374 - (int) frameSizeInBytes;
00375 
00380 - (NSString *) description;
00381 
00387 - (void) findMin: (float *) pMin max: (float *) pMax;
00388 
00396 - (void) findMin: (float *) pMin 
00397               at: (unsigned long *) minLocation 
00398              max: (float *) pMax 
00399               at: (unsigned long *) maxLocation;
00400 
00405 - (float) findMaximumMagnitudeAt: (unsigned long *) sampleIndex;
00406 
00412 - (float) findMaximumMagnitudeAt: (unsigned long *) frameIndex channel: (unsigned int *) channel;
00413 
00420 - (void) amplitudeRMSOfChannels: (float *) rmsAmpPerChannel;
00421 
00426 - (double) maximumAmplitude;
00427 
00435 - (void) normalise;
00436 
00442 - (void) scaleBy: (float) scaleFactor;
00443 
00452 - (float) sampleAtFrameIndex: (unsigned long) frameIndex channel: (int) channel;
00453 
00461 - (BOOL) setSample: (float) sampleValue atFrameIndex: (unsigned long) frameIndex channel: (int) channelNumber;
00462 
00471 - (void) stereoChannels: (int *) leftAndRightChannels;
00472 
00473 @end
00474 
00476 
00477 @interface SndAudioBuffer(SampleConversion)
00478 
00487 - (SndAudioBuffer *) audioBufferConvertedToFormat: (SndSampleFormat) toDataFormat
00488                                      channelCount: (int) toChannelCount
00489                                      samplingRate: (double) toSamplingRate;
00490 
00497 - convertToFormat: (SndFormat) newFormat;
00498 
00506 - convertToSampleFormat: (SndSampleFormat) newDataFormat;
00507 
00525 - (long) convertBytes: (void *) fromDataPtr
00526        intoFrameRange: (NSRange) bufferFrameRange
00527            fromFormat: (SndSampleFormat) fromDataFormat
00528          channelCount: (int) fromChannelCount
00529          samplingRate: (double) fromSamplingRate;
00530 
00540 - convertToSampleFormat: (SndSampleFormat) toDataFormat
00541            channelCount: (int) toChannelCount;
00542 
00557 - convertToSampleFormat: (SndSampleFormat) toDataFormat
00558            channelCount: (int) toChannelCount
00559            samplingRate: (double) toSampleRate
00560          useLargeFilter: (BOOL) largeFilter
00561       interpolateFilter: (BOOL) interpolateFilter
00562  useLinearInterpolation: (BOOL) linearInterpolation;
00563 
00581 SNDKIT_API int SndChangeSampleType(void *fromPtr, void *toPtr, SndSampleFormat dfFrom, SndSampleFormat dfTo, long outCount);
00582 
00605 SNDKIT_API void SndChangeSampleRate(const SndFormat fromSound,
00606                                     void *inputPtr,
00607                                     SndFormat *toSound,
00608                                     short *outPtr,
00609                                     BOOL largeFilter,
00610                                     BOOL interpFilter,
00611                                     BOOL fast);
00612 
00632 SNDKIT_API void SndChannelMap(void *inPtr,
00633                               void *outPtr,
00634                               long frames,
00635                               int oldNumChannels,
00636                               int newNumChannels,
00637                               SndSampleFormat df,
00638                               short *map);
00639 
00640 
00661 SNDKIT_API void SndChannelDecrease(void *inPtr,
00662                                    void *outPtr,
00663                                    unsigned long frames,
00664                                    int oldNumChannels,
00665                                    int newNumChannels,
00666                                    SndSampleFormat df,
00667                                    short *map);
00668 
00669 @end
00670 
00671 #endif