Пример #1
0
void Eyrie::process() {
	if(recbin == NULL) {
		return;
	}
	if(GST_BUFFER_SIZE(buf) == 0) {
		endRecording();
		QVariant ret;
		QMetaObject::invokeMethod(parent(), "setStatus", Q_RETURN_ARG(QVariant, ret), Q_ARG(QVariant, "Sorry, the recording failed."));
		return;
	}
	mutex->lock();
	const float *pcm = (const float *) GST_BUFFER_DATA(buf);
	Codegen *codegen = new Codegen(pcm, GST_BUFFER_SIZE(buf) / sizeof(float), 0);
	mutex->unlock();
	std::string code = codegen->getCodeString();
	QNetworkAccessManager *networkManager = new QNetworkAccessManager();
	QUrl url("http://developer.echonest.com/api/v4/song/identify");
	QByteArray params;
	params.append("api_key=RIUKSNTIPKUMPHPEO");
	params.append("&query=[{\"metadata\":{\"version\":4.12},\"code\":\""); params.append(code.c_str()); params.append("\"}]");
	QNetworkRequest request;
	request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded;charset=UTF-8");
	request.setUrl(url);
	connect(networkManager, SIGNAL(finished(QNetworkReply *)), this, SLOT(parseResponse(QNetworkReply *)));
	networkManager->post(request, params);
}
Пример #2
0
JNIEXPORT jstring JNICALL Java_com_appunite_ffmpeg_FFmpegPlayer_codegen(JNIEnv *env, jobject thiz, jfloatArray pcmData, jint numSamples)
{
	// get the contents of the java array as native floats
	float *data = (float *) env->GetFloatArrayElements(pcmData, 0);
	// invoke the codegen
	Codegen c = Codegen(data, (unsigned int) numSamples, 0);

	const char *code = c.getCodeString().c_str();

	// release the native array as we're done with them
	env->ReleaseFloatArrayElements(pcmData, data, 0);

	// return the fingerprint string
	return env->NewStringUTF(code);
}
JNIEXPORT jstring JNICALL Java_musaic_songRecognizer_Codegen_EchoprintCodegen
  (JNIEnv *env, jobject thiz, jfloatArray javaPcmData, jint numSamples)
{
    // cast de la jfloatArray la float*
    float *pcmData = (float *)env->GetFloatArrayElements(javaPcmData, 0);

    // utilizeaza libraria Echoprint pentru a obtine hashcode-ul
    Codegen c = Codegen(pcmData, (unsigned int)numSamples, 0);
    const char *code = c.getCodeString().c_str();
 
    // elibereaza resursele folosite
    env->ReleaseFloatArrayElements(javaPcmData, pcmData , 0); 
 
    // returneaza hashcode-ul
    return env->NewStringUTF(code);
}
Пример #4
0
static PyObject * echoprint_codegen(PyObject *self, PyObject *args) {
    PyObject *py_samples;
    int start_offset = 0;
    PyObject *item;
    float *samples;
    uint num_samples;
    uint i;
    Codegen *pCodegen;
    PyObject *result;
    std::ostringstream version_string;
    
    if (!PyArg_ParseTuple(args, "O|i", &py_samples, &start_offset)) {
        return NULL;
    }
    if (!PySequence_Check(py_samples)) {
        PyErr_SetString(PyExc_TypeError, "expected sequence");
        return NULL;
    }
    num_samples = PySequence_Size(py_samples);
    samples = new float[num_samples];
    for (i = 0; i < num_samples; i++) {
        item = PySequence_GetItem(py_samples, i);
        if (!PyFloat_Check(item)) {
            delete[] samples;
            PyErr_SetString(PyExc_TypeError, "expected sequence of floats");
            return NULL;
        }
        samples[i] = (float)PyFloat_AsDouble(item);
        Py_DECREF(item);
    }
    pCodegen = new Codegen(samples, num_samples, start_offset);
    version_string << pCodegen->getVersion();
    result = Py_BuildValue("{s:s,s:s}",
        "code", pCodegen->getCodeString().c_str(),
        "version", version_string.str().c_str()
    );
    delete pCodegen;
    delete[] samples;
    return result;
}