Skip to content

Commit

Permalink
Merge pull request #49 from markondej/refactor
Browse files Browse the repository at this point in the history
Refactored code
  • Loading branch information
markondej authored Mar 15, 2017
2 parents 87a0534 + 49c68dc commit c6083ec
Show file tree
Hide file tree
Showing 8 changed files with 227 additions and 396 deletions.
27 changes: 21 additions & 6 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,30 @@
*/

#include <iostream>
#include "wave_reader.h"
#include "transmitter.h"
#include <cstdlib>
#include <csignal>

using namespace std;

bool stop = false;
Transmitter* transmitter = NULL;

AudioFormat* getFormat(string filename) {
stop = false;
WaveReader* reader = new WaveReader(filename, stop);
AudioFormat* format = reader->getFormat();
delete reader;
return format;
}

void sigIntHandler(int sigNum)
{
if (transmitter != NULL) {
cout << "Stopping..." << endl;
transmitter->stop();
stop = true;
}
}

Expand Down Expand Up @@ -80,12 +91,16 @@ int main(int argc, char** argv)
try {
transmitter = Transmitter::getInstance();

AudioFormat* format = Transmitter::getFormat(filename);
cout << "Playing: " << ((filename != "-") ? filename : "stdin") << ", "
<< format->sampleRate << " Hz, "
<< format->bitsPerSample << " bits, "
<< ((format->channels > 0x01) ? "stereo" : "mono") << endl;
delete format;
if (filename != "-") {
AudioFormat* format = getFormat(filename);
cout << "Playing: " << filename << ", "
<< format->sampleRate << " Hz, "
<< format->bitsPerSample << " bits, "
<< ((format->channels > 0x01) ? "stereo" : "mono") << endl;
delete format;
} else {
cout << "Playing: STDIN" << endl;
}

transmitter->play(filename, frequency, loop);
} catch (exception &error) {
Expand Down
7 changes: 2 additions & 5 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ TARGET = fm_transmitter

CPP=$(CCPREFIX)g++

all: main.o error_reporter.o wave_reader.o stdin_reader.o transmitter.o
$(CPP) $(CFLAGS) -o $(TARGET) main.o error_reporter.o wave_reader.o stdin_reader.o transmitter.o
all: main.o error_reporter.o wave_reader.o transmitter.o
$(CPP) $(CFLAGS) -o $(TARGET) main.o error_reporter.o wave_reader.o transmitter.o

wave_reader.o: wave_reader.cpp wave_reader.h
$(CPP) $(CFLAGS) -c wave_reader.cpp

stdin_reader.o: stdin_reader.cpp stdin_reader.h
$(CPP) $(CFLAGS) -c stdin_reader.cpp

error_reporter.o: error_reporter.cpp error_reporter.h
$(CPP) $(CFLAGS) -c error_reporter.cpp

Expand Down
166 changes: 0 additions & 166 deletions stdin_reader.cpp

This file was deleted.

67 changes: 0 additions & 67 deletions stdin_reader.h

This file was deleted.

Loading

0 comments on commit c6083ec

Please sign in to comment.