Mercurial > hg > audiodb
changeset 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 |
files | examples/iAudioDB/AppController.h examples/iAudioDB/AppController.m examples/iAudioDB/iAudioDB.xcodeproj/project.pbxproj |
diffstat | 3 files changed, 24 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/examples/iAudioDB/AppController.h Thu Apr 29 16:36:07 2010 +0000 +++ b/examples/iAudioDB/AppController.h Thu Apr 29 17:15:01 2010 +0000 @@ -97,5 +97,6 @@ -(BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)anItem; -(void)sound:(NSSound *)sound didFinishPlaying:(BOOL)playbackSuccessful; -(void)importFile:(NSString *)filename withExtractorConfig:(NSString *)extractorPath; +-(UInt64)getSampleRate:(NSString *)filename; @end
--- a/examples/iAudioDB/AppController.m Thu Apr 29 16:36:07 2010 +0000 +++ b/examples/iAudioDB/AppController.m Thu Apr 29 17:15:01 2010 +0000 @@ -6,7 +6,7 @@ // Copyright 2010 __MyCompanyName__. All rights reserved. // #import "AppController.h" - +#import <AudioToolbox/AudioFile.h> @implementation AppController @@ -244,17 +244,33 @@ } } +-(UInt64)getSampleRate:(NSString *)filename +{ + AudioFileID audioFile; + AudioFileOpenURL((CFURLRef)[NSURL fileURLWithPath:filename], 0x01, 0, &audioFile); + + UInt32 propertySize; + UInt32 propertyIsWritable; + AudioFileGetPropertyInfo(audioFile, kAudioFilePropertyDataFormat, &propertySize, &propertyIsWritable); + + AudioStreamBasicDescription dataFormat; + AudioFileGetProperty(audioFile, kAudioFilePropertyDataFormat, &propertySize, &dataFormat); + Float64 sampleRate = dataFormat.mSampleRate; + AudioFileClose(audioFile); + + return sampleRate; +} + -(void)importFile:(NSString *)filename withExtractorConfig:(NSString *)extractorPath { // Create the extractor configuration + UInt64 sampleRate = [self getSampleRate:filename]; NSString* extractorContent = [NSString stringWithContentsOfFile:extractorPath]; NSString* hopStr = [dbState objectForKey:@"hopsize"]; NSString* newContent = [[extractorContent stringByReplacingOccurrencesOfString:@"HOP_SIZE" withString:hopStr] stringByReplacingOccurrencesOfString:@"WINDOW_SIZE" withString:[NSString stringWithFormat:@"%d", [hopStr intValue] * 8]]; NSString* n3FileName = [NSTemporaryDirectory() stringByAppendingPathComponent:@"extractor_config.n3"]; - NSLog(extractorContent); - NSLog(newContent); NSError* error; [newContent writeToFile:n3FileName atomically:YES encoding:NSASCIIStringEncoding error:&error];
--- a/examples/iAudioDB/iAudioDB.xcodeproj/project.pbxproj Thu Apr 29 16:36:07 2010 +0000 +++ b/examples/iAudioDB/iAudioDB.xcodeproj/project.pbxproj Thu Apr 29 17:15:01 2010 +0000 @@ -20,6 +20,7 @@ B7CBF33211105F1700B8C1C8 /* AppController.m in Sources */ = {isa = PBXBuildFile; fileRef = B7CBF33111105F1700B8C1C8 /* AppController.m */; }; B7CBF3B711106F4C00B8C1C8 /* libaudioDB.0.0.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = B7CBF3B611106F4C00B8C1C8 /* libaudioDB.0.0.dylib */; }; B7E0FD5B114164430003AB08 /* BWToolkitFramework.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B7E0FD5A114164430003AB08 /* BWToolkitFramework.framework */; }; + B7F9D0151189EFAA0023FEBF /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B7F9D0141189EFAA0023FEBF /* AudioToolbox.framework */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -55,6 +56,7 @@ B7CBF33111105F1700B8C1C8 /* AppController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppController.m; sourceTree = "<group>"; }; B7CBF3B611106F4C00B8C1C8 /* libaudioDB.0.0.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libaudioDB.0.0.dylib; path = /usr/local/lib/libaudioDB.0.0.dylib; sourceTree = "<absolute>"; }; B7E0FD5A114164430003AB08 /* BWToolkitFramework.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = BWToolkitFramework.framework; sourceTree = "<group>"; }; + B7F9D0141189EFAA0023FEBF /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = /System/Library/Frameworks/AudioToolbox.framework; sourceTree = "<absolute>"; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -66,6 +68,7 @@ B7CBF3B711106F4C00B8C1C8 /* libaudioDB.0.0.dylib in Frameworks */, B7E0FD5B114164430003AB08 /* BWToolkitFramework.framework in Frameworks */, B7000BA71180AE2B00C3DAEC /* BWToolkitFramework.framework in Frameworks */, + B7F9D0151189EFAA0023FEBF /* AudioToolbox.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -144,6 +147,7 @@ 29B97323FDCFA39411CA2CEA /* Frameworks */ = { isa = PBXGroup; children = ( + B7F9D0141189EFAA0023FEBF /* AudioToolbox.framework */, B7E0FD5A114164430003AB08 /* BWToolkitFramework.framework */, 1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */, 1058C7A2FEA54F0111CA2CBB /* Other Frameworks */,