File: example.cpp

package info (click to toggle)
libofa 0.9.3-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,932 kB
  • ctags: 460
  • sloc: cpp: 24,470; sh: 8,366; makefile: 45; ansic: 14
file content (72 lines) | stat: -rw-r--r-- 1,770 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* ------------------------------------------------------------------

   libofa -- the Open Fingerprint Architecture library

   Public Domain (PD) 2006 MusicIP Corporation
   No rights reserved.

-------------------------------------------------------------------*/

#include "protocol.h"

AudioData* loadWaveFile(char *file);
AudioData* loadDataUsingLAME(char *file);

int main(int argc, char **argv) {
    AudioData *data = 0;

	// Go through each filename passed on the command line
    for (int i = 1; i < argc; ++i) {
	char *file = argv[i];

	// Get the extension
	char fext[100] = "";
	char *p = strrchr(file, '.');
	if ( p != NULL ) {
	    strcpy(fext, p+1);

	    // Lowercase the extension
	    p = fext;
	    while ( *p ) {
		*p = tolower(*p);
		p++;
	    }
	}

	if ( strstr(fext, "wav") ) {
	    // Process a Wave file
	    printf("Checking file %s\n", file);
	    data = loadWaveFile(file);
	} else {
	    // Handle anything else
	    printf("Decoding file %s\n", file);
	    data = loadDataUsingLAME(file);
	}
	if (!data) {
	    printf("** Failed to load file\n");
	    continue;
	}

	// Get the fingerprint
	if (!data->createPrint()) {
	    printf("** Failed to generate print.\n");
	    delete data;
	    continue;
	}

	// Get the metadata.  Make sure to get your own client id
	// at http://www.musicdns.org before using this in your own application.
	TrackInformation *info = data->getMetadata("a7f6063296c0f1c9b75c7f511861b89b", "Example 0.9.3", true);
	if (!info) {
	    printf("** Failed to get metadata.\n");
	} else {
	    // Print results.
	    printf(" Title: %s\n", info->getTrack().c_str());
	    printf("Artist: %s\n", info->getArtist().c_str());
	    printf("  PUID: %s\n", info->getPUID().c_str());
	}
	delete data;
    }
    return 0;
}