To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Revision:

root / protocol.h @ 1:150ad38c1871

History | View | Annotate | Download (3.65 KB)

1
/* ------------------------------------------------------------------
2

3
   libofa -- the Open Fingerprint Architecture library
4

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

8
-------------------------------------------------------------------*/
9
#ifndef __PROTOCOL_H__
10
#define __PROTOCOL_H__
11

    
12
#include <string>
13
#include "ofa1/ofa.h"
14

    
15
using namespace std;
16

    
17
// This object must be filled out completely prior to making any
18
// calls to the server.  On return, some fields will be filled out.
19
class TrackInformation {
20
private:
21
    string puid;
22
    string print;
23
    string encoding;        // All other strings must honor this encoding
24
    int    bitrate;         // i.e. "192kbps", use 0 for VBR or freeformat
25
    string format;          // File extension
26
    long   length_in_ms;    // In milliseconds
27
    string artist;
28
    string track;
29
    string album;
30
    int    trackNum;        // use 0 if not known
31
    string genre;
32
    string year;
33
public:
34
    TrackInformation() :
35
        bitrate(0), length_in_ms(0), trackNum(0) {}
36
    ~TrackInformation() {}
37
    void setPrint(string p) { print = p; }
38
    string getPrint() const { return print; }
39
    // Only supported encodings are UTF-8 (default) and ISO-8859-15
40
    void setEncoding(string e) { encoding = e; }
41
    string getEncoding() const { return encoding; }
42
    void setBitrate(int b) { bitrate = b; }
43
    int getBitrate() const { return bitrate; }
44
    void setFormat(string fmt) { format = fmt; }
45
    string getFormat() const { return format; }
46
    void setLengthInMS(long ms) { length_in_ms = ms; }
47
    long getLengthInMS() const { return length_in_ms; }
48
    void setArtist(string name) { artist = name; }
49
    string getArtist() const { return artist; }
50
    void setTrack(string name) { track = name; }
51
    string getTrack() const { return track; }
52
    void setAlbum(string name) { album = name; }
53
    string getAlbum() const { return album; }
54
    void setTrackNum(int t) { trackNum = t; }
55
    int getTrackNum() const { return trackNum; }
56
    void setGenre(string g) { genre = g; }
57
    string getGenre() const { return genre; }
58
    void setYear(string y) { year = y; }
59
    string getYear() const { return year; }
60
    void setPUID(string id)  { puid = id; }
61
    string getPUID() const { return puid; }
62
};
63

    
64
// Get your unique key at http://www.musicdns.org
65
bool retrieve_metadata(string client_key, string client_verstion,
66
        TrackInformation *info, bool getMetadata);
67

    
68
class AudioData {
69
private:
70
    unsigned char *samples;
71
    int byteOrder;
72
    long size;
73
    int sRate;
74
    bool stereo;
75
public:
76
    TrackInformation info;
77
    AudioData() : samples(0), size(0), sRate(0), stereo(false) {}
78
    ~AudioData() {
79
        delete[] samples;
80
    }
81
    // size is number of samples (half the number of bytes)
82
    void setData(unsigned char*_samples, int _byteOrder, long _size,
83
                    int _sRate, bool _stereo, int _ms, string _fmt) {
84
        samples = _samples;
85
        byteOrder = _byteOrder;
86
        size = _size;
87
        sRate = _sRate;
88
        stereo = _stereo;
89
        // These two fields are used later for the protocol layer
90
        info.setLengthInMS(_ms);
91
        info.setFormat(_fmt);
92
    }
93
    int getByteOrder() const { return byteOrder; }
94
    long getSize() const { return size; }
95
    int getSRate() const { return sRate; }
96
    bool getStereo() const { return stereo; }
97
    bool createPrint() {
98
        const char *print = ofa_create_print(samples, byteOrder, size, sRate, stereo);
99
        if (!print)
100
            return false;
101
        info.setPrint(print);
102
        return true;
103
    }
104
    // Get your unique key at http://www.musicdns.org
105
    TrackInformation *getMetadata(string client_key, string client_version, 
106
            bool metadataFlag)
107
    {
108
        if (!retrieve_metadata(client_key, client_version, &info, metadataFlag))
109
            return 0;
110
        return &info;
111
    }
112
};
113

    
114
#endif