Skip to content
This repository has been archived by the owner on Mar 28, 2022. It is now read-only.

Refactor code, details below #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/AudioBufferInput.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
// Copyright 2011 The Echo Nest Corporation. All rights reserved.
//

#include <string.h>
#include <limits.h>
#include <assert.h>


#include <cstring>
#include <climits>
#include "AudioBufferInput.h"

AudioBufferInput::AudioBufferInput() { }
Expand Down
8 changes: 2 additions & 6 deletions src/AudioStreamInput.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@



#include <cstring>
#include <stddef.h>
#include <stdio.h>
#include <iostream>
Expand All @@ -18,14 +19,10 @@
#include <winsock.h>
#define POPEN_MODE "rb"
#endif
#include <string.h>

#include "AudioStreamInput.h"
#include "Common.h"
#include "Params.h"

using std::string;

namespace FFMPEG {
// Do we think FFmpeg will read this as an audio file?
bool IsAudioFile(const char* pFileName) {
Expand Down Expand Up @@ -121,8 +118,7 @@ bool AudioStreamInput::ProcessFilePointer(FILE* pFile) {
}
assert(samplesLeft == 0);

int error = ferror(pFile);
bool success = error == 0;
bool success = (ferror(pFile) == 0);

if (!success)
perror("ProcessFilePointer error");
Expand Down
9 changes: 3 additions & 6 deletions src/Codegen.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
#include "Base64.h"
#include <zlib.h>

using std::string;
using std::vector;

Codegen::Codegen(const float* pcm, unsigned int numSamples, int start_offset) {
if (Params::AudioStreamInput::MaxSamples < (uint)numSamples)
throw std::runtime_error("File was too big\n");
Expand All @@ -47,7 +44,7 @@ Codegen::Codegen(const float* pcm, unsigned int numSamples, int start_offset) {
delete pAudio;
}

string Codegen::createCodeString(vector<FPCode> vCodes) {
std::string Codegen::createCodeString(std::vector<FPCode> vCodes) {
if (vCodes.size() < 3) {
return "";
}
Expand All @@ -64,7 +61,7 @@ string Codegen::createCodeString(vector<FPCode> vCodes) {
}


string Codegen::compress(const string& s) {
std::string Codegen::compress(const std::string& s) {
long max_compressed_length = s.size()*2;
unsigned char *compressed = new unsigned char[max_compressed_length];

Expand All @@ -85,7 +82,7 @@ string Codegen::compress(const string& s) {
deflateEnd(&stream);

// base64 the zlib'd code string
string encoded = base64_encode(compressed, compressed_length, true);
std::string encoded = base64_encode(compressed, compressed_length, true);
delete [] compressed;
return encoded;
}
2 changes: 1 addition & 1 deletion src/File.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#ifndef FILE_H
#define FILE_H
#include <string.h>
#include <cstring>
#ifdef _WIN32
#include "win_unistd.h"
#else
Expand Down
2 changes: 1 addition & 1 deletion src/Fingerprint.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "Fingerprint.h"
#include "Params.h"
#include <string.h>
#include <cstring>

#ifdef _WIN32
#include "win_funcs.h"
Expand Down
22 changes: 10 additions & 12 deletions src/main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


#include <stdio.h>
#include <string.h>
#include <cstring>
#include <memory>
#ifndef _WIN32
#include <libgen.h>
Expand All @@ -20,8 +20,6 @@
#include <string>
#define MAX_FILES 200000

using namespace std;

// The response from the codegen. Contains all the fields necessary
// to create a json string.
typedef struct {
Expand Down Expand Up @@ -116,7 +114,7 @@ codegen_response_t *codegen_file(char* filename, int start_offset, int duration,
response->error = NULL;
response->codegen = NULL;

auto_ptr<FfmpegStreamInput> pAudio(new FfmpegStreamInput());
std::auto_ptr<FfmpegStreamInput> pAudio(new FfmpegStreamInput());
pAudio->ProcessFile(filename, start_offset, duration);

if (pAudio.get() == NULL) { // Unable to decode!
Expand All @@ -143,7 +141,7 @@ codegen_response_t *codegen_file(char* filename, int start_offset, int duration,
double t2 = now();
Codegen *pCodegen = new Codegen(pAudio->getSamples(), numSamples, start_offset);
t2 = now() - t2;

response->t1 = t1;
response->t2 = t2;
response->numSamples = numSamples;
Expand All @@ -152,7 +150,7 @@ codegen_response_t *codegen_file(char* filename, int start_offset, int duration,
response->duration = duration;
response->tag = tag;
response->filename = filename;

return response;
}

Expand Down Expand Up @@ -181,13 +179,13 @@ void print_json_to_screen(char* output, int count, int done) {
}

char *make_json_string(codegen_response_t* response) {

if (response->error != NULL) {
return response->error;
}

// Get the ID3 tag information.
auto_ptr<Metadata> pMetadata(new Metadata(response->filename));
std::auto_ptr<Metadata> pMetadata(new Metadata(response->filename));

// preamble + codelen
char* output = (char*) malloc(sizeof(char)*(16384 + strlen(response->codegen->getCodeString().c_str()) ));
Expand Down Expand Up @@ -220,7 +218,7 @@ char *make_json_string(codegen_response_t* response) {
int main(int argc, char** argv) {
if (argc < 2) {
fprintf(stderr, "Usage: %s [ filename | -s ] [seconds_start] [seconds_duration] [< file_list (if -s is set)]\n", argv[0]);
exit(-1);
exit(EXIT_FAILURE);
}

try {
Expand All @@ -235,10 +233,10 @@ int main(int argc, char** argv) {
if (argc > 4) already = atoi(argv[4]);
// If you give it -s, it means to read in a list of files from stdin.
if (strcmp(filename, "-s") == 0) {
while(cin) {
while(std::cin) {
if (count < MAX_FILES) {
string temp_str;
getline(cin, temp_str);
getline(std::cin, temp_str);
if (temp_str.size() > 2)
files[count++] = temp_str;
} else {
Expand Down