cog/Old/Sound.h

134 lines
3.0 KiB
C
Raw Normal View History

2005-06-02 18:16:43 +00:00
//
// Sound.h
// Cog
//
2005-07-02 21:02:06 +00:00
// Created by Vincent Spader on 5/11/05.
// Copyright 2005 Vincent Spader All rights reserved.
2005-06-02 18:16:43 +00:00
//
#import <Cocoa/Cocoa.h>
#import <CoreAudio/AudioHardware.h>
#import <AudioToolbox/AudioToolbox.h>
#import <AudioUnit/AudioUnit.h>
#import "SoundFile/SoundFile.h"
#import "VirtualRingBuffer.h"
//Inter thread messages
//Controller to sound messages
enum
{
kCogPauseResumeMessage = 100,
kCogPauseMessage,
kCogResumeMessage,
kCogPlayFileMessage,
kCogChangeFileMessage,
kCogStopMessage,
kCogSeekMessage,
kCogEndOfPlaylistMessage,
2005-06-29 15:28:20 +00:00
kCogSetVolumeMessage,
2005-06-02 18:16:43 +00:00
//sound to controller
kCogCheckinMessage,
kCogRequestNextFileMessage,
kCogBitrateUpdateMessage,
kCogLengthUpdateMessage,
kCogPositionUpdateMessage,
2005-06-07 04:01:00 +00:00
kCogFileChangedMessage,
kCogStatusUpdateMessage
2005-06-02 18:16:43 +00:00
};
enum
{
2005-06-07 04:01:00 +00:00
kCogStatusPaused = 0,
2005-06-02 18:16:43 +00:00
kCogStatusStopped,
kCogStatusPlaying,
kCogStatusEndOfFile,
kCogStatusEndOfPlaylist,
kCogStatusPlaybackEnded
};
@interface Sound : NSObject {
//For communication with the soundcontroller
NSPort *sendPort;
NSPort *distantPort;
SoundFile *soundFile;
unsigned long currentPosition;
unsigned long totalLength;
//Whole lotta core audio fun
AudioUnit outputUnit;
AudioStreamBasicDescription deviceFormat; // info about the default device
AudioStreamBasicDescription sourceStreamFormat;
AURenderCallbackStruct renderCallback;
AudioConverterRef converter;
void *conversionBuffer;
int playbackStatus;
2005-06-07 04:01:00 +00:00
int oldPlaybackStatus; //For resuming
2005-06-02 18:16:43 +00:00
NSTimer *fillTimer; //used to wake up the filler thread
//semaphore_t semaphore; //used to wake up the filler thread
NSTimer *positionTimer;
VirtualRingBuffer *ringBuffer;
VirtualRingBuffer *auxRingBuffer; //For changing tracks
VirtualRingBuffer *readRingBuffer;
VirtualRingBuffer *writeRingBuffer;
//Track changing procedure...sound send changerequest to controller when it hits EOF, and sets writeringbuffer to the opposite buffer...
//when buffer is empty, sound sends changecomplete to controller, and sets readringbuffer to the opposite
NSLock *readLock;
NSLock *writeLock;
}
- (void)launchThreadWithPort:(id)inData;
- (void)sendPortMessage:(int)msgid;
- (void)sendPortMessage:(int)msgid withData:(void *)data ofSize:(int)size;
- (void)handlePortMessage:(NSPortMessage *)portMessage;
- (void)scheduleFillTimer;
- (void)fireFillTimer;
- (void)sendPositionUpdate:(id)sender;
- (void)fillBuffer:(id)sender;
- (int)convert:(void *)destBuf packets:(int)numPackets;
- (void)resetBuffer;
- (VirtualRingBuffer *)oppositeBuffer:(VirtualRingBuffer *)buf;
2005-09-07 22:33:16 +00:00
//private methods
2005-06-02 18:16:43 +00:00
- (BOOL)setupAudioOutput;
- (BOOL)startAudioOutput;
- (void)stopAudioOutput;
- (void)cleanUpAudioOutput;
- (BOOL)prepareSoundFile;
- (void)cleanUpSoundFile;
- (void)setThreadPolicy;
2005-06-07 04:01:00 +00:00
- (void)setPlaybackStatus:(int)s;
2005-06-02 18:16:43 +00:00
- (void)pause;
- (void)resume;
- (void)stop;
- (void)playFile:(NSString *)filename;
- (void)changeFile:(NSString *)filename;
2005-06-07 21:04:15 +00:00
- (BOOL)setSoundFile:(NSString *)filename;
2005-06-02 18:16:43 +00:00
//helper function
- (double)calculateTime:(unsigned long) pos;
- (unsigned long)calculatePos:(double) time;
2005-06-29 15:28:20 +00:00
- (void)setVolume:(float)v;
2005-06-02 18:16:43 +00:00
@end