# HG changeset patch # User mas01mj # Date 1272639450 0 # Node ID 6d8539709d9c2285a80fd0f5c23cbece3ba07055 # Parent e21abbac820e3548edfc7c022e935bcf12b816c3 Switching over to use sample rate where possible - poss bug in query start specification. diff -r e21abbac820e -r 6d8539709d9c examples/iAudioDB/AppController.h --- a/examples/iAudioDB/AppController.h Thu Apr 29 17:15:01 2010 +0000 +++ b/examples/iAudioDB/AppController.h Fri Apr 30 14:57:30 2010 +0000 @@ -98,5 +98,7 @@ -(void)sound:(NSSound *)sound didFinishPlaying:(BOOL)playbackSuccessful; -(void)importFile:(NSString *)filename withExtractorConfig:(NSString *)extractorPath; -(UInt64)getSampleRate:(NSString *)filename; +-(UInt64)getHopSizeInSamples:(NSString *)filename; +-(int)nearestPow2:(int)x; @end diff -r e21abbac820e -r 6d8539709d9c examples/iAudioDB/AppController.m --- a/examples/iAudioDB/AppController.m Thu Apr 29 17:15:01 2010 +0000 +++ b/examples/iAudioDB/AppController.m Fri Apr 30 14:57:30 2010 +0000 @@ -93,7 +93,8 @@ } // Calculate the max DB size - int vectors = ceil(([maxLengthField doubleValue] * 60.0f) / ([hopSizeField doubleValue] / 44100.0f)); + int vectors = ceil(([maxLengthField doubleValue] * 60.0f) / (([hopSizeField doubleValue] / 1000) * 44100.0f)); + NSLog(@"Vectors: %d", vectors); int numtracks = [maxTracksField intValue]; int datasize = ceil((numtracks * vectors * dim * 8.0f) / 1024.0f / 1024.0f); // In MB @@ -261,17 +262,36 @@ return sampleRate; } +-(UInt64)getHopSizeInSamples:(NSString *)filename +{ + NSString* hopStr = [dbState objectForKey:@"hopsize"]; + return round([self getSampleRate:filename] * ([hopStr doubleValue] / 1000)); +} + +-(int)nearestPow2:(int)x +{ + if (x < 0) + return 0; + --x; + x |= x >> 1; + x |= x >> 2; + x |= x >> 4; + x |= x >> 8; + x |= x >> 16; + return x+1; +} + -(void)importFile:(NSString *)filename withExtractorConfig:(NSString *)extractorPath { // Create the extractor configuration - UInt64 sampleRate = [self getSampleRate:filename]; + int hopSizeSamples = [self getHopSizeInSamples:filename]; + int windowSizeSamples = [self nearestPow2:(hopSizeSamples*8)]; 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* newContent = [[extractorContent stringByReplacingOccurrencesOfString:@"HOP_SIZE" withString:[NSString stringWithFormat:@"%d", hopSizeSamples]] + stringByReplacingOccurrencesOfString:@"WINDOW_SIZE" withString:[NSString stringWithFormat:@"%d", windowSizeSamples]]; NSString* n3FileName = [NSTemporaryDirectory() stringByAppendingPathComponent:@"extractor_config.n3"]; - + NSLog(newContent); NSError* error; [newContent writeToFile:n3FileName atomically:YES encoding:NSASCIIStringEncoding error:&error]; @@ -315,7 +335,6 @@ /** * Choose the file(s) to be imported. - * TODO: Currently handles the import process too - split this off. */ -(IBAction)importAudio:(id)sender { @@ -338,18 +357,6 @@ NSString* extractor = [dbState objectForKey:@"extractor"]; NSString* extractorPath = [NSString stringWithFormat:@"/Applications/iAudioDB.app/rdf/%@.n3", extractor]; - // TODO Shift this process into a separate function. - // Create the customized extractor config -/* NSString* extractorContent = [NSString stringWithContentsOfFile:extractorPath]; - NSString* hopStr = [dbState objectForKey:@"hopsize"]; - NSString* winStr = [dbState objectForKey:@"windowsize"]; - NSString* newContent = [[extractorContent stringByReplacingOccurrencesOfString:@"HOP_SIZE" withString:hopStr] - stringByReplacingOccurrencesOfString:@"WINDOW_SIZE" withString:winStr]; - NSString* n3FileName = [NSTemporaryDirectory() stringByAppendingPathComponent:@"extractor_config.n3"]; - - NSError* error; - [newContent writeToFile:n3FileName atomically:YES encoding:NSASCIIStringEncoding error:&error]; -*/ for(int i=0; i<[filesToOpen count]; i++) { audiodb_close(db); @@ -357,42 +364,6 @@ // Get the sample rate for the audio file [self importFile:[filesToOpen objectAtIndex:i] withExtractorConfig:extractorPath]; - - /* NSString* tempFileTemplate = [NSTemporaryDirectory() stringByAppendingPathComponent:@"features.XXXXXX"]; - const char* tempFileTemplateCString = [tempFileTemplate fileSystemRepresentation]; - char* tempFileNameCString = (char *)malloc(strlen(tempFileTemplateCString) + 1); - strcpy(tempFileNameCString, tempFileTemplateCString); - mktemp(tempFileNameCString); - - NSString* featuresFileName = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:tempFileNameCString length:strlen(tempFileNameCString)]; - free(tempFileNameCString); - - NSTask* task = [[NSTask alloc] init]; - - [task setLaunchPath:@"/usr/local/bin/sonic-annotator"]; - NSArray* args; - args = [NSArray arrayWithObjects:@"-t", n3FileName, @"-w", @"rdf", @"-r", @"--rdf-network", @"--rdf-one-file", featuresFileName, @"--rdf-force", [filesToOpen objectAtIndex:i], nil]; - [task setArguments:args]; - [task launch]; - [task waitUntilExit]; - [task release]; - - NSTask* importTask = [[NSTask alloc] init]; - [importTask setLaunchPath:@"/usr/local/bin/populate"]; - args = [NSArray arrayWithObjects:featuresFileName, dbFilename, nil]; - [importTask setArguments:args]; - [importTask launch]; - [importTask waitUntilExit]; - [importTask release]; - - NSString* val = [[filesToOpen objectAtIndex:i] retain]; - NSString* key = [[[filesToOpen objectAtIndex:i] lastPathComponent] retain]; - - // Update the plist store. - [trackMap setValue:val forKey:key]; - [dbState writeToFile:plistFilename atomically: YES]; - */ - db = audiodb_open([dbFilename cStringUsingEncoding:NSUTF8StringEncoding], O_RDONLY); [self updateStatus]; } @@ -648,9 +619,11 @@ { queryTrack = [[NSSound alloc] initWithContentsOfFile:selectedFilename byReference:YES]; - double samples = ([queryTrack duration]*44100.0f); - double hopSize = [[dbState objectForKey:@"hopsize"] doubleValue]; - double winSize = [[dbState objectForKey:@"windowsize"] doubleValue]; + int sampleRate = [self getSampleRate:selectedFilename]; + int hopSize = [self getHopSizeInSamples:selectedFilename]; + int winSize = [self nearestPow2:(hopSize*8)]; + + double samples = ([queryTrack duration]*sampleRate); [queryLengthSeconds setDoubleValue:[queryTrack duration]]; [queryLengthVectors setDoubleValue:ceil((samples-winSize)/hopSize)]; @@ -665,6 +638,7 @@ [queryStartVectors setEnabled:YES]; [resetButton setEnabled:YES]; [multipleCheckBox setEnabled:YES]; + [queryButton setEnabled:YES]; } @@ -672,8 +646,9 @@ { NSTextField *ed = [nd object]; - double hopSize = [[dbState objectForKey:@"hopsize"] doubleValue]; - double winSize = [[dbState objectForKey:@"windowsize"] doubleValue]; + int sampleRate = [self getSampleRate:selectedFilename]; + int hopSize = [self getHopSizeInSamples:selectedFilename]; + int winSize = [self nearestPow2:(hopSize*8)]; if(!queryTrack) { @@ -681,9 +656,10 @@ } double totalDuration = [queryTrack duration]; - double samples = totalDuration * 44100.0f; + double samples = totalDuration * sampleRate; double totalVectors = ceil((samples-winSize)/hopSize); + double lengthSecs = [queryLengthSeconds doubleValue]; double startSecs = [queryStartSeconds doubleValue]; double lengthVectors = [queryLengthVectors doubleValue]; @@ -694,10 +670,9 @@ { if(lengthSecs >= 0) { - lengthVectors = ceil(((lengthSecs*44100.0f)-winSize)/hopSize); + lengthVectors = ceil(((lengthSecs*sampleRate)-winSize)/hopSize); if(lengthVectors < 0) {lengthVectors = 0; } [queryLengthVectors setDoubleValue:lengthVectors]; - } } @@ -705,7 +680,7 @@ { if(lengthVectors >= 0) { - lengthSecs = ((hopSize*lengthVectors)+winSize)/44100.0f; + lengthSecs = ((hopSize*lengthVectors)+winSize)/sampleRate; if(lengthSecs < 0) { lengthSecs = 0; } [queryLengthSeconds setDoubleValue:lengthSecs]; } @@ -716,7 +691,7 @@ { if(startSecs >= 0) { - startVectors = ceil(((startSecs*44100.0f)-winSize)/hopSize); + startVectors = ceil(((startSecs*sampleRate)-winSize)/hopSize); if(startVectors < 0) { startVectors = 0; } [queryStartVectors setDoubleValue:startVectors]; } @@ -725,7 +700,7 @@ { if(startVectors >= 0) { - startSecs = ((hopSize*startVectors)+winSize)/44100.0f; + startSecs = ((hopSize*startVectors)+winSize)/sampleRate; if(startSecs < 0) { startSecs = 0; } [queryStartSeconds setDoubleValue:startSecs]; } @@ -813,11 +788,16 @@ } else { + NSLog(@"Populate table: %d", result->nresults); - float divisor = (44100.0f/hopSize); for(int i=0; inresults; i++) { + NSString* filename = [trackMap objectForKey:[NSString stringWithFormat:@"%s", result->results[i].ikey]]; + int sampleRate = [self getSampleRate:filename]; + int hopSize = [self getHopSizeInSamples:filename]; + float divisor = (sampleRate/hopSize); + NSMutableDictionary* dict = [[NSMutableDictionary alloc] initWithCapacity:4]; [dict setValue:[NSString stringWithFormat:@"%s", result->results[i].ikey] forKey:@"key"]; [dict setValue:[NSNumber numberWithFloat:result->results[i].dist] forKey:@"distance"]; diff -r e21abbac820e -r 6d8539709d9c examples/iAudioDB/English.lproj/MainMenu.xib --- a/examples/iAudioDB/English.lproj/MainMenu.xib Thu Apr 29 17:15:01 2010 +0000 +++ b/examples/iAudioDB/English.lproj/MainMenu.xib Fri Apr 30 14:57:30 2010 +0000 @@ -8,10 +8,11 @@ 353.00 YES + + + + - - - YES @@ -899,7 +900,7 @@ 17 2 - {{196, 229}, {305, 281}} + {{196, 278}, {305, 232}} -1543503872 Create NSPanel @@ -913,9 +914,8 @@ 268 - {{20, 155}, {176, 86}} + {{20, 106}, {176, 86}} - YES 4 1 @@ -1199,9 +1199,8 @@ 268 - {{17, 249}, {123, 17}} + {{17, 200}, {123, 17}} - YES 68288064 @@ -1218,7 +1217,6 @@ 268 {{99, 12}, {96, 32}} - YES -2080244224 @@ -1239,7 +1237,6 @@ 268 {{195, 12}, {96, 32}} - YES -2080244224 @@ -1258,9 +1255,8 @@ 268 - {{198, 249}, {117, 17}} + {{198, 200}, {117, 17}} - YES 68288064 @@ -1275,9 +1271,8 @@ 268 - {{201, 219}, {84, 22}} + {{201, 170}, {84, 22}} - YES -1804468671 @@ -1293,9 +1288,8 @@ 268 - {{198, 194}, {182, 17}} + {{198, 145}, {182, 17}} - YES 68288064 @@ -1310,9 +1304,8 @@ 268 - {{201, 164}, {84, 22}} + {{201, 115}, {84, 22}} - YES -1804468671 @@ -1328,14 +1321,13 @@ 268 - {{198, 139}, {182, 17}} + {{198, 90}, {182, 17}} - YES 68288064 272630784 - Slice Size (s): + Slice Size (ms): @@ -1345,14 +1337,13 @@ 268 - {{201, 109}, {84, 22}} + {{201, 60}, {84, 22}} - YES -1804468671 272630784 - 2048 + 50 YES @@ -1360,45 +1351,9 @@ - - - 268 - {{198, 84}, {182, 17}} - - - YES - - 68288064 - 272630784 - Window Size: - - - - - - - - - 268 - {{201, 54}, {84, 22}} - - - YES - - -1804468671 - 272630784 - 16384 - - - YES - - - - - {305, 281} + {305, 232} - {{0, 0}, {1280, 1002}} {3.40282e+38, 3.40282e+38} @@ -2040,14 +1995,6 @@ - windowSizeField - - - - 791 - - - querySheet @@ -2603,10 +2550,8 @@ - - + - @@ -2857,34 +2802,6 @@ - 787 - - - YES - - - - - - 788 - - - YES - - - - - - 789 - - - - - 790 - - - - 792 @@ -3431,10 +3348,6 @@ 778.NSWindowTemplate.visibleAtLaunch 779.IBPluginDependency 780.IBPluginDependency - 787.IBPluginDependency - 788.IBPluginDependency - 789.IBPluginDependency - 790.IBPluginDependency 792.IBEditorWindowLastContentRect 792.IBWindowTemplateEditedContentRect 792.NSWindowTemplate.visibleAtLaunch @@ -3558,8 +3471,8 @@ {74, 862} {{6, 978}, {478, 20}} - {{194, -257}, {606, 477}} - {{194, -257}, {606, 477}} + {{38, 68}, {606, 477}} + {{38, 68}, {606, 477}} {{33, 99}, {480, 360}} {3.40282e+38, 3.40282e+38} @@ -3575,8 +3488,8 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{413, 467}, {305, 281}} - {{413, 467}, {305, 281}} + {{413, 516}, {305, 232}} + {{413, 516}, {305, 232}} com.apple.InterfaceBuilder.CocoaPlugin {{83, 102}, {201, 183}} @@ -3621,17 +3534,13 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{76, 497}, {528, 56}} - {{76, 497}, {528, 56}} + {{26, 698}, {528, 56}} + {{26, 698}, {528, 56}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - {{154, 421}, {294, 331}} - {{154, 421}, {294, 331}} + {{453, 577}, {294, 331}} + {{453, 577}, {294, 331}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -3800,7 +3709,6 @@ statusField stopButton tracksView - windowSizeField YES @@ -3829,7 +3737,6 @@ NSTextField NSToolbarItem NSTableView - NSTextField