Browse Source
- View with rulers - FFT with Accelerated framework - Opening music from iTunes (almost) TODO: ducktape things togethermaster
Joshua Moerman
11 years ago
10 changed files with 473 additions and 19 deletions
@ -0,0 +1,5 @@ |
|||
|
|||
*xcworkspace |
|||
*xcuserdata |
|||
build |
|||
|
@ -0,0 +1,68 @@ |
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
|||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB" version="3.0" toolsVersion="4514" systemVersion="13B42" targetRuntime="iOS.CocoaTouch.iPad" propertyAccessControl="none" useAutolayout="YES"> |
|||
<dependencies> |
|||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="4514"/> |
|||
</dependencies> |
|||
<objects> |
|||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="ViewController"> |
|||
<connections> |
|||
<outlet property="contentView" destination="1" id="waQ-1e-XtN"/> |
|||
</connections> |
|||
</placeholder> |
|||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> |
|||
<view contentMode="scaleToFill" id="1"> |
|||
<rect key="frame" x="0.0" y="0.0" width="534" height="376"/> |
|||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> |
|||
<subviews> |
|||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="qOE-WQ-xv7"> |
|||
<rect key="frame" x="414" y="256" width="100" height="100"/> |
|||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> |
|||
<color key="backgroundColor" red="0.40000000600000002" green="1" blue="0.80000001190000003" alpha="1" colorSpace="calibratedRGB"/> |
|||
<constraints> |
|||
<constraint firstAttribute="height" constant="100" id="20Q-nP-HWg"/> |
|||
<constraint firstAttribute="width" constant="100" id="Isk-N0-p0Z"/> |
|||
</constraints> |
|||
</view> |
|||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="V5r-JV-Fkh"> |
|||
<rect key="frame" x="414" y="20" width="100" height="100"/> |
|||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> |
|||
<color key="backgroundColor" red="0.80000001192092896" green="1" blue="0.40000000596046448" alpha="1" colorSpace="calibratedRGB"/> |
|||
<constraints> |
|||
<constraint firstAttribute="width" constant="100" id="GAt-IV-PXp"/> |
|||
<constraint firstAttribute="height" constant="100" id="eYY-eK-hai"/> |
|||
</constraints> |
|||
</view> |
|||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="xhz-dx-nq1"> |
|||
<rect key="frame" x="20" y="20" width="100" height="100"/> |
|||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> |
|||
<color key="backgroundColor" red="1" green="0.80000001192092896" blue="0.40000000596046448" alpha="1" colorSpace="calibratedRGB"/> |
|||
<constraints> |
|||
<constraint firstAttribute="height" constant="100" id="L4i-fJ-6Ko"/> |
|||
<constraint firstAttribute="width" constant="100" id="ym9-zy-Fdt"/> |
|||
</constraints> |
|||
</view> |
|||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="01T-Bq-eRq"> |
|||
<rect key="frame" x="20" y="256" width="100" height="100"/> |
|||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> |
|||
<color key="backgroundColor" red="1" green="0.43529412150382996" blue="0.81176471710205078" alpha="1" colorSpace="calibratedRGB"/> |
|||
<constraints> |
|||
<constraint firstAttribute="height" constant="100" id="Vc9-mU-Out"/> |
|||
<constraint firstAttribute="width" constant="100" id="zza-hp-DTx"/> |
|||
</constraints> |
|||
</view> |
|||
</subviews> |
|||
<color key="backgroundColor" red="1" green="0.40000000596046448" blue="0.40000000596046448" alpha="1" colorSpace="calibratedRGB"/> |
|||
<constraints> |
|||
<constraint firstItem="01T-Bq-eRq" firstAttribute="leading" secondItem="1" secondAttribute="leading" constant="20" id="D6I-ib-Jul"/> |
|||
<constraint firstAttribute="trailing" secondItem="V5r-JV-Fkh" secondAttribute="trailing" constant="20" id="Jx3-5I-Mar"/> |
|||
<constraint firstItem="xhz-dx-nq1" firstAttribute="top" secondItem="1" secondAttribute="top" constant="20" id="MPA-2Y-2Ax"/> |
|||
<constraint firstItem="xhz-dx-nq1" firstAttribute="leading" secondItem="1" secondAttribute="leading" constant="20" id="TSQ-mb-8WP"/> |
|||
<constraint firstAttribute="bottom" secondItem="qOE-WQ-xv7" secondAttribute="bottom" constant="20" id="cwF-Rs-2Ma"/> |
|||
<constraint firstItem="V5r-JV-Fkh" firstAttribute="top" secondItem="1" secondAttribute="top" constant="20" id="lta-Lt-WYv"/> |
|||
<constraint firstAttribute="trailing" secondItem="qOE-WQ-xv7" secondAttribute="trailing" constant="20" id="oNF-uM-mJr"/> |
|||
<constraint firstAttribute="bottom" secondItem="01T-Bq-eRq" secondAttribute="bottom" constant="20" id="qi3-cZ-ZFw"/> |
|||
</constraints> |
|||
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/> |
|||
</view> |
|||
</objects> |
|||
</document> |
@ -0,0 +1,14 @@ |
|||
//
|
|||
// FFTTest.h
|
|||
// SpectogramPrototype
|
|||
//
|
|||
// Created by Joshua Moerman on 24/12/13.
|
|||
// Copyright (c) 2013 Joshua Moerman. All rights reserved.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
|
|||
@interface FFTTest : NSObject |
|||
- (void) inPlaceFFT:(float*)data forSize:(unsigned int)n; |
|||
@property (readonly) unsigned int acceptedSize; |
|||
@end |
@ -0,0 +1,77 @@ |
|||
// |
|||
// FFTTest.m |
|||
// SpectogramPrototype |
|||
// |
|||
// Created by Joshua Moerman on 24/12/13. |
|||
// Copyright (c) 2013 Joshua Moerman. All rights reserved. |
|||
// |
|||
|
|||
#import "FFTTest.h" |
|||
#import <Accelerate/Accelerate.h> |
|||
|
|||
@interface FFTTest () { |
|||
FFTSetup setup; |
|||
float * window; |
|||
float * buffer; |
|||
} |
|||
|
|||
@end |
|||
|
|||
const int logN = 3; |
|||
const int N = 1 << logN; |
|||
const float scaling = 1.0 / N; |
|||
|
|||
@implementation FFTTest |
|||
@synthesize acceptedSize; |
|||
|
|||
- (id)init{ |
|||
if(self = [super init]){ |
|||
acceptedSize = N; |
|||
|
|||
setup = vDSP_create_fftsetup(logN, kFFTRadix2); |
|||
window = calloc(N, sizeof(float)); |
|||
buffer = calloc(N, sizeof(float)); |
|||
|
|||
assert(setup && window && buffer); |
|||
} |
|||
return self; |
|||
} |
|||
|
|||
- (void)dealloc{ |
|||
free(buffer); |
|||
free(window); |
|||
vDSP_destroy_fftsetup(setup); |
|||
} |
|||
|
|||
- (void)inPlaceFFT:(float *)data forSize:(unsigned int)n{ |
|||
assert(n == N); |
|||
|
|||
// Output the source data |
|||
for(int i = 0; i < N; ++i){ |
|||
printf("%f, ", data[i]); |
|||
} |
|||
printf("\n"); |
|||
|
|||
// Window our time - slice |
|||
// vDSP_blkman_window(window, N, 0); |
|||
// vmul(data, 1, window, 1, data, 1, N); |
|||
|
|||
// Rearrange data |
|||
DSPSplitComplex split_buffer = { buffer, buffer + N/2 }; |
|||
vDSP_ctoz((DSPComplex *)data, 2, &split_buffer, 1, N/2); |
|||
|
|||
// DO IT! |
|||
vDSP_fft_zrip(setup, &split_buffer, 1, logN, FFT_FORWARD); |
|||
|
|||
// Calculates magnitudes (so ignores phases) |
|||
vDSP_zvabs(&split_buffer, 1, data, 1, N/2); |
|||
vDSP_vsmul(data, 1, &scaling, data, 1, N/2); |
|||
|
|||
// Output results: |
|||
for(int i = 0; i < N/2; ++i){ |
|||
printf("%f, ", data[i]); |
|||
} |
|||
printf("\n"); |
|||
|
|||
} |
|||
@end |
@ -0,0 +1,15 @@ |
|||
//
|
|||
// RuledScrollView.h
|
|||
// SpectogramPrototype
|
|||
//
|
|||
// Created by Joshua Moerman on 24/12/13.
|
|||
// Copyright (c) 2013 Joshua Moerman. All rights reserved.
|
|||
//
|
|||
|
|||
#import <UIKit/UIKit.h> |
|||
|
|||
@interface RuledScrollView : UIScrollView |
|||
@property (nonatomic, readonly) UIView * content; |
|||
@property (nonatomic, readonly) UIView * topRuler; |
|||
@property (nonatomic, readonly) UIView * leftRuler; |
|||
@end |
@ -0,0 +1,109 @@ |
|||
// |
|||
// RuledScrollView.m |
|||
// SpectogramPrototype |
|||
// |
|||
// Created by Joshua Moerman on 24/12/13. |
|||
// Copyright (c) 2013 Joshua Moerman. All rights reserved. |
|||
// |
|||
|
|||
#import "RuledScrollView.h" |
|||
|
|||
@interface RuledScrollView () <UIScrollViewDelegate> { |
|||
CGFloat rulerHeight; |
|||
CGFloat rulerWidth; |
|||
} |
|||
- (void) initView; |
|||
- (void) placeTicks; |
|||
@end |
|||
|
|||
@implementation RuledScrollView |
|||
@synthesize content, topRuler, leftRuler; |
|||
|
|||
- (id)initWithFrame:(CGRect)frame{ |
|||
if(self = [super initWithFrame:frame]){ |
|||
[self initView]; |
|||
} |
|||
return self; |
|||
} |
|||
|
|||
- (id)initWithCoder:(NSCoder *)aDecoder{ |
|||
if(self = [super initWithCoder:aDecoder]){ |
|||
[self initView]; |
|||
} |
|||
return self; |
|||
} |
|||
|
|||
- (void)initView { |
|||
rulerHeight = 44; |
|||
rulerWidth = 120; |
|||
|
|||
self.delegate = self; |
|||
self.backgroundColor = [UIColor whiteColor]; |
|||
|
|||
content = [[UIView alloc] initWithFrame:self.frame]; |
|||
content.autoresizesSubviews = NO; |
|||
[self addSubview:content]; |
|||
|
|||
CGRect frame2 = self.frame; |
|||
frame2.size.height = rulerHeight; |
|||
topRuler = [[UIView alloc] initWithFrame:frame2]; |
|||
topRuler.layer.opacity = 0.5; |
|||
topRuler.backgroundColor = self.backgroundColor; |
|||
[self addSubview:topRuler]; |
|||
|
|||
CGRect frame3 = self.frame; |
|||
frame3.size.width = rulerWidth; |
|||
leftRuler = [[UIView alloc] initWithFrame:frame3]; |
|||
leftRuler.layer.opacity = 0.5; |
|||
leftRuler.backgroundColor = self.backgroundColor; |
|||
[self addSubview:leftRuler]; |
|||
} |
|||
|
|||
/* we should draw the ticks in drawRect: |
|||
[[UIColor blackColor] setFill]; |
|||
UIRectFill((CGRect){0,200,rect.size.width,1}); |
|||
|
|||
and do tiling for the text |
|||
*/ |
|||
|
|||
- (void)placeTicks { |
|||
[topRuler.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)]; |
|||
for (CGFloat x = rulerWidth + 50; x < topRuler.frame.size.width; x += 100){ |
|||
UIView * line = [[UIView alloc] initWithFrame:CGRectMake(x, 0, 1, rulerHeight)]; |
|||
line.backgroundColor = [UIColor blackColor]; |
|||
[topRuler addSubview:line]; |
|||
|
|||
CGFloat width = 100; |
|||
UILabel * text = [[UILabel alloc] initWithFrame:CGRectMake(x - width/2, 0, width, rulerHeight)]; |
|||
text.text = [NSString stringWithFormat:@"%.0f", x]; |
|||
text.textAlignment = NSTextAlignmentCenter; |
|||
[topRuler addSubview:text]; |
|||
} |
|||
} |
|||
|
|||
- (void)layoutSubviews { |
|||
{ |
|||
CGRect frame = self.topRuler.frame; |
|||
frame.origin.y = self.contentOffset.y; |
|||
self.topRuler.frame = frame; |
|||
[self placeTicks]; |
|||
} |
|||
{ |
|||
CGRect frame = self.leftRuler.frame; |
|||
frame.origin.x = self.contentOffset.x; |
|||
self.leftRuler.frame = frame; |
|||
} |
|||
} |
|||
|
|||
- (void)setContentSize:(CGSize)contentSize{ |
|||
[super setContentSize:CGSizeMake(contentSize.width + rulerWidth, contentSize.height + rulerHeight)]; |
|||
content.frame = CGRectMake(rulerWidth, rulerHeight, contentSize.width, contentSize.height); |
|||
topRuler.frame = CGRectMake(0, 0, contentSize.width + rulerWidth, rulerHeight); |
|||
leftRuler.frame = CGRectMake(0, 0, rulerWidth, contentSize.height + rulerHeight); |
|||
} |
|||
|
|||
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{ |
|||
return content; |
|||
} |
|||
|
|||
@end |
Reference in new issue