Forums: 

Hi. I'm trying to read a 16bit 16KHz wav (20 seconds long) from on iOS and perform a fingerprint identification. I tried following the guide "GNSDK-for-Mobile-iOS-Developers-Guide" but it doesn't have an objective-c example on page 53 (only C#).  My code reads in the whole file and then writes 2K blocks to the function fingerprintWrite (I've also tried passing a pointer to  the whole file). The variable "result' is never set to 1 - indicating insufficient data has been passed - but 20 seconds should be enough, right? Can anyone help? Thanks.

This is what I have done:

 

        NSString *filepath = [[NSBundle mainBundle] pathForResource:@"Human.signed.20s.16bit" ofType:@"raw"];

        NSData *audioData= [NSData dataWithContentsOfFile:filepath];

        BOOL result;

        

        if (error)

            NSLog(@"Error reading file: %@", error.localizedDescription);

        

        // for debugging...

        NSLog(@"contents: %@", audioData);

        NSLog(@"Done:");

        unsigned char buffer[audioData.length];

        [audioData getBytes:buffer length:audioData.length];

        for (int i = 0; i < audioData.length; i++) {

            printf("0x%02x ",(unsigned char)buffer[i]);

        }

    

        [self.gnMusicIDFileInfo fingerprintBegin:16000 audioSampleSize:16 audioChannels:1 error:&error];

        if (error) {

            NSLog(@"Error = %@", [error localizedDescription]);

        }

        

        int count = 0;

        result = 0;

        while (result==0 && count<sizeof(buffer)-2048)

        {

            result = [self.gnMusicIDFileInfo fingerprintWrite:&buffer[count] audioDataSize:2048 error:&error];

            NSLog(@"Count = %i",count);

            count=count+2048;

        }

        

        NSLog(@"result = %i", result);

        if (error) {

            NSLog(@"Error = %@", [error localizedDescription]);

        }

        

        [self.gnMusicIDFileInfo fingerprintEnd:&error];

        if (error) {

            NSLog(@"Error = %@", [error localizedDescription]);

        }

        

        [self.gnMusicIDFileInfo fingerprint:&error];

        if (error) {

            NSLog(@"Error = %@", [error localizedDescription]);

        }

Hi,
Thank you for the question.
20 seconds may not be enough because the identification process requires enough amount of "usable" audio to proceed. Also, when doing a MusicID File identification, it is required to have the audio file from the beginning of a song. If your use case provides only part of a song and the song does not start from the beginning, it will most likely not work. You will need to use MusicID Stream instead.
Hope this helps,

Forum Discussions