2015-02-08 23:15:02 -03:00
|
|
|
//
|
|
|
|
// SilenceDecoder.m
|
|
|
|
// Cog
|
|
|
|
//
|
|
|
|
// Created by Christopher Snowhill on 2/8/15.
|
|
|
|
// Copyright 2015 __NoWork, LLC__. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "SilenceDecoder.h"
|
|
|
|
|
|
|
|
#import "Logging.h"
|
|
|
|
|
|
|
|
#import "PlaylistController.h"
|
|
|
|
|
|
|
|
@implementation SilenceDecoder
|
|
|
|
|
|
|
|
enum { sample_rate = 44100 };
|
|
|
|
enum { channels = 2 };
|
|
|
|
|
2022-02-07 02:49:27 -03:00
|
|
|
- (BOOL)open:(id<CogSource>)s {
|
|
|
|
[self setSource:s];
|
|
|
|
|
|
|
|
NSString *path = [[[s url] relativeString] substringFromIndex:10];
|
|
|
|
|
|
|
|
int seconds = [path intValue];
|
|
|
|
if(!seconds) seconds = 10;
|
|
|
|
|
|
|
|
length = seconds * sample_rate;
|
|
|
|
remain = length;
|
|
|
|
|
|
|
|
[self willChangeValueForKey:@"properties"];
|
2015-02-08 23:15:02 -03:00
|
|
|
[self didChangeValueForKey:@"properties"];
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2022-02-07 02:49:27 -03:00
|
|
|
- (NSDictionary *)properties {
|
2022-02-09 00:42:03 -03:00
|
|
|
return @{@"bitrate": [NSNumber numberWithInt:0],
|
|
|
|
@"sampleRate": [NSNumber numberWithFloat:sample_rate],
|
|
|
|
@"totalFrames": [NSNumber numberWithDouble:length],
|
|
|
|
@"bitsPerSample": [NSNumber numberWithInt:32],
|
|
|
|
@"floatingPoint": [NSNumber numberWithBool:YES],
|
|
|
|
@"channels": [NSNumber numberWithInt:channels],
|
|
|
|
@"seekable": [NSNumber numberWithBool:YES],
|
|
|
|
@"endian": @"host",
|
|
|
|
@"encoding": @"synthesized"};
|
2015-02-08 23:15:02 -03:00
|
|
|
}
|
|
|
|
|
2022-02-09 00:56:39 -03:00
|
|
|
- (NSDictionary *)metadata {
|
|
|
|
return @{};
|
|
|
|
}
|
|
|
|
|
2022-02-07 02:49:27 -03:00
|
|
|
- (int)readAudio:(void *)buf frames:(UInt32)frames {
|
|
|
|
int total = frames;
|
|
|
|
|
|
|
|
if(!IsRepeatOneSet()) {
|
|
|
|
if(total > remain)
|
|
|
|
total = (int)remain;
|
|
|
|
|
|
|
|
remain -= total;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(buf, 0, sizeof(float) * total * channels);
|
|
|
|
|
|
|
|
return total;
|
2015-02-08 23:15:02 -03:00
|
|
|
}
|
|
|
|
|
2022-02-07 02:49:27 -03:00
|
|
|
- (long)seek:(long)frame {
|
|
|
|
if(frame > length)
|
|
|
|
frame = length;
|
|
|
|
|
|
|
|
remain = length - frame;
|
|
|
|
|
|
|
|
return frame;
|
2015-02-08 23:15:02 -03:00
|
|
|
}
|
|
|
|
|
2022-02-07 02:49:27 -03:00
|
|
|
- (void)close {
|
2015-02-08 23:15:02 -03:00
|
|
|
}
|
|
|
|
|
2022-02-07 02:49:27 -03:00
|
|
|
- (void)setSource:(id<CogSource>)s {
|
2015-02-08 23:15:02 -03:00
|
|
|
source = s;
|
|
|
|
}
|
|
|
|
|
2022-02-07 02:49:27 -03:00
|
|
|
- (id<CogSource>)source {
|
2015-02-08 23:15:02 -03:00
|
|
|
return source;
|
|
|
|
}
|
|
|
|
|
2022-02-07 02:49:27 -03:00
|
|
|
+ (NSArray *)fileTypes {
|
2022-01-18 23:12:57 -03:00
|
|
|
return @[];
|
2015-02-08 23:15:02 -03:00
|
|
|
}
|
|
|
|
|
2022-02-07 02:49:27 -03:00
|
|
|
+ (NSArray *)mimeTypes {
|
2022-01-18 23:12:57 -03:00
|
|
|
return @[@"audio/x-silence"];
|
2015-02-08 23:15:02 -03:00
|
|
|
}
|
|
|
|
|
2022-02-07 02:49:27 -03:00
|
|
|
+ (float)priority {
|
|
|
|
return 1.0;
|
2015-02-08 23:15:02 -03:00
|
|
|
}
|
|
|
|
|
2022-01-18 22:30:07 -03:00
|
|
|
+ (NSArray *)fileTypeAssociations {
|
2022-02-07 02:49:27 -03:00
|
|
|
return @[];
|
2022-01-18 22:30:07 -03:00
|
|
|
}
|
|
|
|
|
2015-02-08 23:15:02 -03:00
|
|
|
@end
|