-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release version 0.01 of audio-recognition: Finish codes on linux ubuntu
- Loading branch information
Showing
16 changed files
with
351 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
CINC = -Iinclude | ||
SRC = src | ||
BIN = bin | ||
CC = g++ -Wall -O3 -Wno-unused-result $(CINC) | ||
|
||
all: ${BIN}/build ${BIN}/recog | ||
|
||
# Generates a compiler for an d_lang language, | ||
${BIN}/build: $(SRC)/build.cpp $(SRC)/hash.cpp $(SRC)/fingerprint.cpp $(SRC)/wav.cpp $(SRC)/bmp.cpp | ||
mkdir -p ${BIN} | ||
$(CC) -o $(BIN)/build $(SRC)/build.cpp $(SRC)/hash.cpp $(SRC)/fingerprint.cpp $(SRC)/bmp.cpp $(SRC)/wav.cpp -ll -lm -lfftw3 | ||
|
||
${BIN}/recog: $(SRC)/recog.cpp $(SRC)/hash.cpp $(SRC)/fingerprint.cpp $(SRC)/wav.cpp $(SRC)/bmp.cpp | ||
mkdir -p ${BIN} | ||
$(CC) -o $(BIN)/recog $(SRC)/recog.cpp $(SRC)/hash.cpp $(SRC)/fingerprint.cpp $(SRC)/bmp.cpp $(SRC)/wav.cpp -ll -lm -lfftw3 | ||
|
||
clean: | ||
rm -f *.BAK *.o core *~* *.a | ||
rm -f $(BIN)/build | ||
rm -f $(BIN)/recog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,40 @@ | ||
Robust Music/Audio Recognition Algorithm in C++ | ||
Music/Audio Recognition Application written in C++ | ||
=============================================== | ||
|
||
Features: | ||
----- | ||
* Robust Audio Recognition | ||
* High efficiency (recognize in less than 0.1 second per song) | ||
* Memory reduction ( 4G is enough for 10000 songs) | ||
* The Data Structure now support 2,500,000 songs and each song less than 7 minutes. | ||
* return the TIME POINT of the cut song in original song. | ||
|
||
Dependencies: | ||
----- | ||
* fftw3: | ||
If under Debian/Ubuntu, run `apt-get install libfftw3-dev`. | ||
|
||
Compile & Run: | ||
----- | ||
* extract songs to ./bin/ dir. | ||
* `make` to produce two excutive files in ./bin/ | ||
* The songs should be .wav format. | ||
* The songs should be contained in ./bin/samples/ | ||
* You may download the songs. | ||
link: | ||
password: | ||
* run `cd bin`, `./build` and it'll produce a file called `database` | ||
* run `./recog ${filename}` to recog the songs that in samples list. | ||
|
||
TODO: | ||
----- | ||
- Transfer the codes from windows to linux. | ||
- Android app to test the algorithm interactively. | ||
- The Http request/response and such hustle and bustle. | ||
- ... | ||
- Docs | ||
|
||
DONE: | ||
----- | ||
- Solve the BaiduMusic download tools. | ||
- All the codes in Windows. | ||
- Transfer the codes from windows to linux. | ||
- Solve the BaiduMusic download tools to update new songs automatically. | ||
|
||
My partner and I finshed this project on Windows8 and got the *First Prize* delivered by [National Engineering Laboratory for Speech and Language Informatinon Processing](http://nelslip.ustc.edu.cn/html/yunews/detail_2014_05/30/191.shtml). | ||
At the begining, it's a COMPETITION. My partner and I finshed this project on Windows8 and won the *First Prize* delivered by [National Engineering Laboratory for Speech and Language Informatinon Processing](http://nelslip.ustc.edu.cn/html/yunews/detail_2014_05/30/191.shtml). | ||
Feel free to contact me yjh199511 at gmail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef BMP_H | ||
#define BMP_H | ||
|
||
#define BMP_TEST | ||
|
||
#include <iostream> | ||
#include <assert.h> | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#define checkborder(x,y) (x>=0 && x<W && y>=0 && y<H) | ||
using namespace std; | ||
|
||
class TBMP{ | ||
private: | ||
char **bitmap; | ||
FILE *fp; | ||
public: | ||
int W, H; | ||
int MODE; | ||
//int R, G, B; | ||
int Grey; | ||
TBMP(const char *filename, int w, int h, int mode); | ||
~TBMP(); | ||
int setcolor(int grey); | ||
int drawpoint(int x, int y); | ||
int drawline(int x0, int y0, int x1, int y1); | ||
int drawrect(int x0, int y0, int x1, int y1); | ||
}; | ||
|
||
#endif |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
#include "bmp.h" | ||
|
||
TBMP::TBMP(const char *filename, int w, int h, int mode){ | ||
#ifdef BMP_TEST | ||
char bufferc[4]; | ||
/* char ch = 255; */ | ||
unsigned long buffer4; | ||
unsigned short buffer2; | ||
|
||
fp = fopen(filename, "wb"); | ||
if (fp == NULL) printf("!!"); | ||
W = w; | ||
H = h; | ||
MODE = mode%2; | ||
if (W%4!=0) W=(W/4+1)*4; | ||
|
||
int i, j; | ||
bitmap = (char **)malloc(H * sizeof(char *)); | ||
if (bitmap == NULL) printf("00"); | ||
for(i=0; i<H; i++){ | ||
bitmap[i] = (char *)malloc(W * sizeof(char)); | ||
assert(bitmap[i]!=NULL); | ||
} | ||
for (j=0; j<H; j++) | ||
for (i=0; i<W; i++){ | ||
bitmap[j][i] = 255; | ||
} | ||
|
||
//bitmap-file header (14 Bytes) | ||
fwrite("BM", 1, 2, fp); //0000h 2 bfType | ||
buffer4 = W*H + 1078; | ||
fwrite(&buffer4, 4, 1, fp); //0002h 4 bfSize | ||
buffer4 = 0; | ||
fwrite(&buffer4, 1, 4, fp); //0006h 4 bfReserved | ||
buffer4 = 1078; | ||
fwrite(&buffer4, 4, 1, fp); //000Ah 4 bfOffbits | ||
|
||
//bitmap-information header (40 Bytes) | ||
buffer4 = 0x28; | ||
fwrite(&buffer4, 4, 1, fp); //000Eh 4 biSize | ||
buffer4 = W; | ||
fwrite(&buffer4, 4, 1, fp); //0012h 4 biWidth | ||
buffer4 = H; | ||
fwrite(&buffer4, 4, 1, fp); //0016h 4 biHeight | ||
buffer2 = 1; | ||
fwrite(&buffer2, 2, 1, fp); //001Ah 2 biPlanes | ||
buffer2 = 8; | ||
fwrite(&buffer2, 2, 1, fp); //001Ch 2 biBitCount (8bit 256色) | ||
buffer4 = 0; | ||
fwrite(&buffer4, 4, 1, fp); //001Eh 4 biCompression | ||
buffer4 = 0; | ||
fwrite(&buffer4, 4, 1, fp); //0022h 4 biSizeImage | ||
buffer4 = 0; | ||
fwrite(&buffer4, 4, 1, fp); //0026h 4 biXPelsPerMeter | ||
buffer4 = 0; | ||
fwrite(&buffer4, 4, 1, fp); //002Ah 4 biYPelsPerMeter | ||
buffer4 = 256; | ||
fwrite(&buffer4, 4, 1, fp); //002Eh 4 biClrUsed (256色调色板) | ||
buffer4 = 256; | ||
fwrite(&buffer4, 4, 1, fp); //0032h 4 biClrImportant (256个重要颜色索引) | ||
|
||
//color table (1024 Bytes) | ||
bufferc[3] = 0; | ||
for (i=0; i<256; i++){ | ||
bufferc[0] = i; | ||
bufferc[1] = i; | ||
bufferc[2] = i; | ||
fwrite(bufferc, 1, 4, fp); | ||
} | ||
#endif | ||
} | ||
|
||
TBMP::~TBMP(){ | ||
#ifdef BMP_TEST | ||
//data (W*H Bytes) | ||
for (int j=H-1; j>=0; j--) | ||
fwrite(bitmap[j], 1, W, fp); | ||
fclose(fp); | ||
//realease resources | ||
#endif | ||
} | ||
|
||
int TBMP::setcolor(int grey){ | ||
#ifdef BMP_TEST | ||
if (grey<0 || grey>255) | ||
return 1; | ||
|
||
Grey = grey; | ||
return 0; | ||
#endif | ||
} | ||
|
||
int TBMP::drawpoint(int x, int y){ | ||
#ifdef BMP_TEST | ||
if (!checkborder(x,y)) | ||
return 1; | ||
|
||
if (MODE) | ||
bitmap[H-1-y][x] = Grey; | ||
else | ||
bitmap[y][x] = Grey; | ||
return 0; | ||
#endif | ||
} | ||
|
||
int TBMP::drawline(int x0, int y0, int x1, int y1){ | ||
#ifdef BMP_TEST | ||
if (!checkborder(x0, y0) || !checkborder(x1, y1)) | ||
return 1; | ||
if (x0==x1 && y0==y1) | ||
return drawpoint(x0, y0); | ||
|
||
int xs, ys, xe, ye; | ||
int i, j; | ||
double t; | ||
if (abs(x0-x1) >= abs(y0-y1)){ | ||
if (x0 < x1){ | ||
xs = x0; | ||
ys = y0; | ||
xe = x1; | ||
ye = y1; | ||
} | ||
else{ | ||
xs = x1; | ||
ys = y1; | ||
xe = x0; | ||
ye = y0; | ||
} | ||
t = (double)(ye - ys) / (double)(xe - xs); | ||
for (i=xs; i<=xe; i++){ | ||
j = (int)((i - xs) * t + ys); | ||
drawpoint(i,j); | ||
//bitmap[j][i] = Grey; | ||
} | ||
} | ||
else{ | ||
if (y0 < y1){ | ||
xs = x0; | ||
ys = y0; | ||
xe = x1; | ||
ye = y1; | ||
} | ||
else{ | ||
xs = x1; | ||
ys = y1; | ||
xe = x0; | ||
ye = y0; | ||
} | ||
t = (double)(xe - xs) / (double)(ye - ys); | ||
for (j=ys; j<=ye; j++){ | ||
i = (int)((j-ys) * t + xs); | ||
drawpoint(i,j); | ||
//bitmap[j][i] =Grey; | ||
} | ||
} | ||
return 0; | ||
#endif | ||
} | ||
|
||
int TBMP::drawrect(int x0, int y0, int x1, int y1){ | ||
#ifdef BMP_TEST | ||
return drawline(x0, y0, x0, y1) || drawline(x0, y0, x1, y0) \ | ||
|| drawline(x1, y0, x1, y1) || drawline(x0, y1, x1, y1); | ||
#endif | ||
} |
Oops, something went wrong.