Mercurial > hg > audiodb
comparison examples/iAudioDB/AppController.m @ 701:e21abbac820e
Now grabs sample rate from audio file. Next step - removal of hop size in samples.
author | mas01mj |
---|---|
date | Thu, 29 Apr 2010 17:15:01 +0000 |
parents | 54974e8a6b87 |
children | 6d8539709d9c |
comparison
equal
deleted
inserted
replaced
700:54974e8a6b87 | 701:e21abbac820e |
---|---|
4 // | 4 // |
5 // Created by Mike Jewell on 27/01/2010. | 5 // Created by Mike Jewell on 27/01/2010. |
6 // Copyright 2010 __MyCompanyName__. All rights reserved. | 6 // Copyright 2010 __MyCompanyName__. All rights reserved. |
7 // | 7 // |
8 #import "AppController.h" | 8 #import "AppController.h" |
9 | 9 #import <AudioToolbox/AudioFile.h> |
10 | 10 |
11 | 11 |
12 @implementation AppController | 12 @implementation AppController |
13 | 13 |
14 -(id)init | 14 -(id)init |
242 [playResultButton setEnabled:NO]; | 242 [playResultButton setEnabled:NO]; |
243 [stopButton setEnabled:NO]; | 243 [stopButton setEnabled:NO]; |
244 } | 244 } |
245 } | 245 } |
246 | 246 |
247 -(UInt64)getSampleRate:(NSString *)filename | |
248 { | |
249 AudioFileID audioFile; | |
250 AudioFileOpenURL((CFURLRef)[NSURL fileURLWithPath:filename], 0x01, 0, &audioFile); | |
251 | |
252 UInt32 propertySize; | |
253 UInt32 propertyIsWritable; | |
254 AudioFileGetPropertyInfo(audioFile, kAudioFilePropertyDataFormat, &propertySize, &propertyIsWritable); | |
255 | |
256 AudioStreamBasicDescription dataFormat; | |
257 AudioFileGetProperty(audioFile, kAudioFilePropertyDataFormat, &propertySize, &dataFormat); | |
258 Float64 sampleRate = dataFormat.mSampleRate; | |
259 AudioFileClose(audioFile); | |
260 | |
261 return sampleRate; | |
262 } | |
263 | |
247 -(void)importFile:(NSString *)filename withExtractorConfig:(NSString *)extractorPath | 264 -(void)importFile:(NSString *)filename withExtractorConfig:(NSString *)extractorPath |
248 { | 265 { |
249 // Create the extractor configuration | 266 // Create the extractor configuration |
267 UInt64 sampleRate = [self getSampleRate:filename]; | |
250 | 268 |
251 NSString* extractorContent = [NSString stringWithContentsOfFile:extractorPath]; | 269 NSString* extractorContent = [NSString stringWithContentsOfFile:extractorPath]; |
252 NSString* hopStr = [dbState objectForKey:@"hopsize"]; | 270 NSString* hopStr = [dbState objectForKey:@"hopsize"]; |
253 NSString* newContent = [[extractorContent stringByReplacingOccurrencesOfString:@"HOP_SIZE" withString:hopStr] | 271 NSString* newContent = [[extractorContent stringByReplacingOccurrencesOfString:@"HOP_SIZE" withString:hopStr] |
254 stringByReplacingOccurrencesOfString:@"WINDOW_SIZE" withString:[NSString stringWithFormat:@"%d", [hopStr intValue] * 8]]; | 272 stringByReplacingOccurrencesOfString:@"WINDOW_SIZE" withString:[NSString stringWithFormat:@"%d", [hopStr intValue] * 8]]; |
255 NSString* n3FileName = [NSTemporaryDirectory() stringByAppendingPathComponent:@"extractor_config.n3"]; | 273 NSString* n3FileName = [NSTemporaryDirectory() stringByAppendingPathComponent:@"extractor_config.n3"]; |
256 NSLog(extractorContent); | |
257 NSLog(newContent); | |
258 | 274 |
259 NSError* error; | 275 NSError* error; |
260 [newContent writeToFile:n3FileName atomically:YES encoding:NSASCIIStringEncoding error:&error]; | 276 [newContent writeToFile:n3FileName atomically:YES encoding:NSASCIIStringEncoding error:&error]; |
261 | 277 |
262 // Create the temp file for the extracted features | 278 // Create the temp file for the extracted features |