Skip to content

Commit

Permalink
Added pitch shifting to play example
Browse files Browse the repository at this point in the history
  • Loading branch information
syedhali committed May 5, 2014
1 parent afcfa79 commit ddadfc5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,22 @@
*/
@property (nonatomic,weak) IBOutlet NSSlider *framePositionSlider;

/**
A slider to adjust the sample rate.
*/
@property (nonatomic,weak) IBOutlet NSSlider *sampleRateSlider;

/**
A BOOL indicating whether or not we've reached the end of the file
*/
@property (nonatomic,assign) BOOL eof;

#pragma mark - Actions
/**
Changes the sampling frequency on the output unit
*/
-(IBAction)changeOutputSamplingFrequency:(id)sender;

/**
Switches the plot drawing type between a buffer plot (visualizes the current stream of audio data from the update function) or a rolling plot (visualizes the audio data over time, this is the classic waveform look)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ -(void)awakeFromNib {
Customizing the audio plot's look
*/
// Background color
self.audioPlot.backgroundColor = [NSColor colorWithCalibratedRed: 0.816 green: 0.349 blue: 0.255 alpha: 1];
self.audioPlot.backgroundColor = [NSColor colorWithCalibratedRed: 0.175 green: 0.151 blue: 0.137 alpha: 1];
// Waveform color
self.audioPlot.color = [NSColor colorWithCalibratedRed: 1.000 green: 1.000 blue: 1.000 alpha: 1];
// Plot type
Expand Down Expand Up @@ -104,6 +104,14 @@ -(void)changePlotType:(id)sender {
}
}

-(void)changeOutputSamplingFrequency:(id)sender
{
AudioStreamBasicDescription asbd = [EZOutput sharedOutput].audioStreamBasicDescription;
float samplingFrequency = ((NSSlider *)sender).floatValue;
asbd.mSampleRate = samplingFrequency;
[[EZOutput sharedOutput] setAudioStreamBasicDescription:asbd];
}

-(void)openFile:(id)sender {
NSOpenPanel* openDlg = [NSOpenPanel openPanel];
openDlg.canChooseFiles = YES;
Expand Down Expand Up @@ -176,7 +184,13 @@ -(void)openFileWithFilePathURL:(NSURL*)filePathURL {
self.plotSegmentControl.selectedSegment = 1;

// Set the client format from the EZAudioFile on the output
[[EZOutput sharedOutput] setAudioStreamBasicDescription:self.audioFile.clientFormat];

#pragma mark Mess Around With Audio Stream Basic Description Here!
self.sampleRateSlider.floatValue = self.audioFile.clientFormat.mSampleRate;
AudioStreamBasicDescription outputASBD = self.audioFile.clientFormat;

[[EZOutput sharedOutput] setAudioStreamBasicDescription:outputASBD];


// Plot the whole waveform
self.audioPlot.plotType = EZPlotTypeBuffer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="4514" systemVersion="13A603" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="4514" systemVersion="13B42" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment version="1070" identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="4514"/>
Expand All @@ -12,6 +12,7 @@
<outlet property="framePositionSlider" destination="CFP-v0-TzQ" id="3oy-Xn-4JK"/>
<outlet property="playButton" destination="OQp-Lr-dlS" id="K5R-Qg-7DY"/>
<outlet property="plotSegmentControl" destination="bZW-tA-C61" id="4ic-Ou-qh2"/>
<outlet property="sampleRateSlider" destination="rRH-oS-VV3" id="8ij-Ff-CZK"/>
<outlet property="view" destination="Xpo-HP-Ost" id="zlj-bW-4iz"/>
</connections>
</customObject>
Expand Down Expand Up @@ -40,8 +41,8 @@
<action selector="openFile:" target="-2" id="3QB-hU-LDl"/>
</connections>
</button>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="0eT-7c-7fJ">
<rect key="frame" x="141" y="235" width="321" height="17"/>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="0eT-7c-7fJ">
<rect key="frame" x="141" y="235" width="38" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="truncatingMiddle" sendsActionOnEndEditing="YES" title="Label" id="vXQ-HF-vLX">
<font key="font" metaFont="system"/>
Expand Down Expand Up @@ -86,6 +87,14 @@
<action selector="seekToFrame:" target="-2" id="iVY-so-6X2"/>
</connections>
</slider>
<slider verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="rRH-oS-VV3">
<rect key="frame" x="141" y="199" width="96" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<sliderCell key="cell" state="on" alignment="left" minValue="8000" maxValue="88200" doubleValue="44100" tickMarkPosition="above" sliderType="linear" id="xbX-Ce-da5"/>
<connections>
<action selector="changeOutputSamplingFrequency:" target="-2" id="yWM-Ei-ztA"/>
</connections>
</slider>
</subviews>
<constraints>
<constraint firstItem="CFP-v0-TzQ" firstAttribute="top" secondItem="OQp-Lr-dlS" secondAttribute="bottom" constant="20" id="6uf-rh-zEf"/>
Expand Down

0 comments on commit ddadfc5

Please sign in to comment.