/** *@internal * Gets the GnMusicIdFileInfo object at the requested position * @param pos [in] the index of obect to retrieve *@endinternal */ GnMusicIdFileInfo get_data(gnsdk_uint32_t pos) const { gnsdk_musicidfile_fileinfo_handle_t fileinfo_handle = GNSDK_NULL; if ( pos < GN_UINT32_MAX) { gnsdk_error_t error = gnsdk_musicidfile_query_fileinfo_get_by_index(weakhandle_, pos-1, &fileinfo_handle); if (GNSDKERR_SEVERE(error)) { throw GnError();} if (!error) return GnMusicIdFileInfo(weakhandle_, fileinfo_handle); } return GnMusicIdFileInfo(); }
static gnsdk_void_t GNSDK_CALLBACK_API _get_fingerprint_callback( const gnsdk_void_t* user_data, gnsdk_musicidfile_query_handle_t query_handle, gnsdk_musicidfile_fileinfo_handle_t fileinfo_handle, gnsdk_uint32_t current_file, gnsdk_uint32_t total_files, gnsdk_bool_t* p_abort ) { gnsdk_error_t error = GNSDK_SUCCESS; gnsdk_bool_t complete = GNSDK_FALSE; gnsdk_cstr_t file = GNSDK_NULL; size_t read = 0; FILE* p_file = NULL; char pcm_audio[2048] = {0}; /* get the file */ error = gnsdk_musicidfile_fileinfo_metadata_get(fileinfo_handle, GNSDK_MUSICIDFILE_FILEINFO_VALUE_FILENAME, &file, GNSDK_NULL); if (GNSDK_SUCCESS != error) { _display_error(__LINE__, "gnsdk_musicidfile_fileinfo_metadata_get() failed", error); return; } /* check file for existence */ p_file = fopen(file, "rb"); if (p_file == NULL) { printf("\n\n!!!!Failed to open input file: %s!!!\n\n", file); return; } /* skip the wave header (first 44 bytes). we know the format of our sample files */ if (0 != fseek(p_file, 44, SEEK_SET)) { GNSDK_ASSERT(0); fclose(p_file); return; } /* initialize the fingerprinter Note: Our sample files are non-standard 11025 Hz 16-bit mono to save on file size */ error = gnsdk_musicidfile_fileinfo_fingerprint_begin( fileinfo_handle, 11025, 16, 1 ); if (GNSDK_SUCCESS != error) { _display_error(__LINE__, "gnsdk_musicidfile_fileinfo_fingerprint_begin() failed", error); fclose(p_file); return; } read = fread(pcm_audio, sizeof(char), 2048, p_file); while (read > 0) { /* write audio to the fingerprinter */ error = gnsdk_musicidfile_fileinfo_fingerprint_write( fileinfo_handle, pcm_audio, read, &complete ); if (GNSDK_SUCCESS != error) { if (GNSDKERR_SEVERE(error)) /* 'aborted' warnings could come back from write which should be expected */ _display_error(__LINE__, "gnsdk_musicidfile_fileinfo_fingerprint_write() failed", error); break; } /* does the fingerprinter have enough audio? */ if (GNSDK_TRUE == complete) { break; } read = fread(pcm_audio, sizeof(char), 2048, p_file); } fclose(p_file); /* signal that we are done */ if (GNSDK_SUCCESS == error) { error = gnsdk_musicidfile_fileinfo_fingerprint_end( fileinfo_handle ); if (GNSDK_SUCCESS != error) { _display_error(__LINE__, "gnsdk_musicidfile_fileinfo_fingerprint_end() failed", error); } } if (GNSDK_TRUE != complete) { /* fingerprinter doesn't have enough data! */ printf("Warning: input file does not contain enough data to generate a fingerprint:\n%s\n", file); } /* this app doesn't allow a user to cancel but you could use this parameter to allow cancellation of the query */ *p_abort = GNSDK_FALSE; /* This is to quiet compiler warnings about un-used parameters in this simplified sample callback. */ user_data = 0; current_file = 0; total_files = 0; (void)query_handle; }
/* This function simulates streaming audio into the Query handle to generate the query fingerprint */ static int _set_query_fingerprint( gnsdk_musicid_query_handle_t query_handle ) { gnsdk_error_t error = GNSDK_SUCCESS; gnsdk_bool_t* p_blocks_complete = NULL; gnsdk_cstr_t file = GNSDK_NULL; size_t read = 0; FILE* p_file = NULL; char pcm_audio[2048] = {0}; int rc = 0; file = "data/05-Hummingbird-sample.wav"; /* check file for existence */ p_file = fopen(file, "rb"); if (p_file == NULL) { printf("\n\n!!!!Failed to open input file: %s!!!\n\n", file); return -1; } /* skip the wave header (first 44 bytes). we know the format of our sample files */ if (0 != fseek(p_file, 44, SEEK_SET)) { fclose(p_file); return -1; } /* initialize the fingerprinter Note: The sample file shipped is a 44100Hz 16-bit stereo (2 channel) wav file */ error = gnsdk_musicid_query_fingerprint_begin( query_handle, GNSDK_MUSICID_FP_DATA_TYPE_GNFPX, 44100, 16, 2 ); if (GNSDK_SUCCESS != error) { _display_error(__LINE__, "gnsdk_musicidfile_fileinfo_fingerprint_begin()", error); fclose(p_file); return -1; } read = fread(pcm_audio, sizeof(char), 2048, p_file); while (read > 0) { /* write audio to the fingerprinter */ error = gnsdk_musicid_query_fingerprint_write( query_handle, pcm_audio, read, p_blocks_complete ); if (GNSDK_SUCCESS != error) { if (GNSDKERR_SEVERE(error)) /* 'aborted' warnings could come back from write which should be expected */ { _display_error(__LINE__, "gnsdk_musicidfile_fileinfo_fingerprint_write()", error); } rc = -1; break; } read = fread(pcm_audio, sizeof(char), 2048, p_file); } fclose(p_file); /*signal that we are done*/ if (GNSDK_SUCCESS == error) { error = gnsdk_musicid_query_fingerprint_end(query_handle); if (GNSDK_SUCCESS != error) { _display_error(__LINE__, "gnsdk_musicidfile_fileinfo_fingerprint_end()", error); } } return rc; }