Skip to content

Commit

Permalink
Merge pull request #82 from markondej/c++11_update
Browse files Browse the repository at this point in the history
C++11 Update
  • Loading branch information
markondej authored Sep 25, 2019
2 parents 18a754e + 01fe181 commit 75ef315
Show file tree
Hide file tree
Showing 13 changed files with 621 additions and 691 deletions.
9 changes: 7 additions & 2 deletions error_reporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@
WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "error_reporter.h"
#include "error_reporter.hpp"

ErrorReporter::ErrorReporter(string message) :
ErrorReporter::ErrorReporter() :
errorMessage(std::string())
{
}

ErrorReporter::ErrorReporter(std::string message) :
errorMessage(message)
{
}
Expand Down
16 changes: 7 additions & 9 deletions error_reporter.h → error_reporter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,22 @@
WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef ERROR_REPORTER_H
#define ERROR_REPORTER_H
#ifndef ERROR_REPORTER_HPP
#define ERROR_REPORTER_HPP

#include <exception>
#include <string>

using std::exception;
using std::string;

class ErrorReporter : public exception
class ErrorReporter : public std::exception
{
public:
explicit ErrorReporter(string message);
ErrorReporter();
ErrorReporter(std::string message);
virtual ~ErrorReporter() throw();

virtual const char *what() const throw();
protected:
string errorMessage;
std::string errorMessage;
};

#endif // ERROR_REPORTER_H
#endif // ERROR_REPORTER_HPP
30 changes: 14 additions & 16 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,19 @@
WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "transmitter.h"
#include "transmitter.hpp"
#include <cstdlib>
#include <csignal>
#include <iostream>
#include <unistd.h>

using namespace std;

bool play = true;
Transmitter *transmitter = NULL;

void sigIntHandler(int sigNum)
{
if (transmitter != NULL) {
cout << "Stopping..." << endl;
std::cout << "Stopping..." << std::endl;
transmitter->stop();
play = false;
}
Expand All @@ -55,9 +53,9 @@ int main(int argc, char** argv)
{
double frequency = 100.0;
double bandwidth = 100.0;
unsigned short dmaChannel = 0;
uint16_t dmaChannel = 0;
bool loop = false;
string filename;
std::string filename;
bool showUsage = true;
int opt, filesOffset;

Expand All @@ -76,7 +74,7 @@ int main(int argc, char** argv)
bandwidth = ::atof(optarg);
break;
case 'v':
cout << EXECUTABLE << " version: " << VERSION << endl;
std::cout << EXECUTABLE << " version: " << VERSION << std::endl;
return 0;
}
}
Expand All @@ -85,7 +83,7 @@ int main(int argc, char** argv)
showUsage = false;
}
if (showUsage) {
cout << "Usage: " << EXECUTABLE << " [-f <frequency>] [-b <bandwidth>] [-d <dma_channel>] [-r] <file>" << endl;
std::cout << "Usage: " << EXECUTABLE << " [-f <frequency>] [-b <bandwidth>] [-d <dma_channel>] [-r] <file>" << std::endl;
return 0;
}

Expand All @@ -99,18 +97,18 @@ int main(int argc, char** argv)
if ((optind == argc) && loop) {
optind = filesOffset;
}
WaveReader reader(filename != "-" ? filename : string(), play);
WaveReader reader(filename != "-" ? filename : std::string(), play);
PCMWaveHeader header = reader.getHeader();
cout << "Broadcasting at " << frequency << " MHz with "
<< bandwidth << " kHz bandwidth" << endl;
cout << "Playing: " << reader.getFilename() << ", "
std::cout << "Broadcasting at " << frequency << " MHz with "
<< bandwidth << " kHz bandwidth" << std::endl;
std::cout << "Playing: " << reader.getFilename() << ", "
<< header.sampleRate << " Hz, "
<< header.bitsPerSample << " bits, "
<< ((header.channels > 0x01) ? "stereo" : "mono") << endl;
transmitter->play(reader, frequency, bandwidth, dmaChannel, optind < argc);
<< ((header.channels > 0x01) ? "stereo" : "mono") << std::endl;
transmitter->transmit(reader, frequency, bandwidth, dmaChannel, optind < argc);
} while (play && (optind < argc));
} catch (exception &error) {
cout << "Error: " << error.what() << endl;
} catch (std::exception &catched) {
std::cout << "Error: " << catched.what() << std::endl;
return 1;
}

Expand Down
19 changes: 8 additions & 11 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
EXECUTABLE = fm_transmitter
VERSION = 0.9.1
FLAGS = -Wall -O3
VERSION = 0.9.3
FLAGS = -Wall -O3 -std=c++11

all: main.o mailbox.o error_reporter.o sample.o preemp.o wave_reader.o transmitter.o
g++ -L/opt/vc/lib -lm -lpthread -lbcm_host -o $(EXECUTABLE) main.o mailbox.o sample.o preemp.o error_reporter.o wave_reader.o transmitter.o
all: main.o mailbox.o error_reporter.o sample.o wave_reader.o transmitter.o
g++ -L/opt/vc/lib -lm -lpthread -lbcm_host -o $(EXECUTABLE) main.o mailbox.o sample.o error_reporter.o wave_reader.o transmitter.o

mailbox.o: mailbox.c mailbox.h
g++ $(FLAGS) -c mailbox.c

error_reporter.o: error_reporter.cpp error_reporter.h
error_reporter.o: error_reporter.cpp error_reporter.hpp
g++ $(FLAGS) -c error_reporter.cpp

sample.o: sample.cpp sample.h
sample.o: sample.cpp sample.hpp
g++ $(FLAGS) -c sample.cpp

preemp.o: preemp.cpp preemp.h
g++ $(FLAGS) -c preemp.cpp

wave_reader.o: wave_reader.cpp wave_reader.h
wave_reader.o: wave_reader.cpp wave_reader.hpp
g++ $(FLAGS) -c wave_reader.cpp

transmitter.o: transmitter.cpp transmitter.h
transmitter.o: transmitter.cpp transmitter.hpp
g++ $(FLAGS) -fno-strict-aliasing -I/opt/vc/include -c transmitter.cpp

main.o: main.cpp
Expand Down
114 changes: 58 additions & 56 deletions pcm_wave_header.h → pcm_wave_header.hpp
Original file line number Diff line number Diff line change
@@ -1,56 +1,58 @@
/*
fm_transmitter - use Raspberry Pi as FM transmitter
Copyright (c) 2019, Marcin Kondej
All rights reserved.
See https://github.com/markondej/fm_transmitter
Redistribution and use in source and binary forms, with or without modification, are
permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be
used to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef PCM_WAVE_HEADER_H
#define PCM_WAVE_HEADER_H

#define WAVE_FORMAT_PCM 0x0001

struct PCMWaveHeader
{
char chunkID[4];
unsigned chunkSize;
char format[4];
char subchunk1ID[4];
unsigned subchunk1Size;
unsigned short audioFormat;
unsigned short channels;
unsigned sampleRate;
unsigned byteRate;
unsigned short blockAlign;
unsigned short bitsPerSample;
char subchunk2ID[4];
unsigned subchunk2Size;
};

#endif // PCM_WAVE_HEADER
/*
fm_transmitter - use Raspberry Pi as FM transmitter
Copyright (c) 2019, Marcin Kondej
All rights reserved.
See https://github.com/markondej/fm_transmitter
Redistribution and use in source and binary forms, with or without modification, are
permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be
used to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef PCM_WAVE_HEADER_HPP
#define PCM_WAVE_HEADER_HPP

#include <cstdint>

#define WAVE_FORMAT_PCM 0x0001

struct PCMWaveHeader
{
int8_t chunkID[4];
uint32_t chunkSize;
int8_t format[4];
int8_t subchunk1ID[4];
uint32_t subchunk1Size;
uint16_t audioFormat;
uint16_t channels;
uint32_t sampleRate;
uint32_t byteRate;
uint16_t blockAlign;
uint16_t bitsPerSample;
int8_t subchunk2ID[4];
uint32_t subchunk2Size;
};

#endif // PCM_WAVE_HEADER_HPP
58 changes: 0 additions & 58 deletions preemp.cpp

This file was deleted.

48 changes: 0 additions & 48 deletions preemp.h

This file was deleted.

Loading

0 comments on commit 75ef315

Please sign in to comment.