Verified Commit 0bdee309 authored by Matthew Burket's avatar Matthew Burket
Browse files

Add the method for AFSK, and creating tones

parent 77ba7416
Pipeline #365 failed with stages
in 20 seconds
//
// Created by Matthew Burket on 10/18/18.
//
#include "eas.h"
#include <math.h>
#include <string>
#include "audio.h"
using namespace std;
/// Add the wave data to the given double vector
/// \param freq freqeunce of the tone in hertz
/// \param vector vector to add samples to
/// \param length length in number of samples
void Audio::generate_tone(double freq, std::vector<double> &vector, long length) {
for (int i = 0; i < length; i++) {
vector.push_back(sin((i * 2 * M_PI * freq) / SAMPLE_RATE));
}
}
void Audio::generate_dual_tone(double freq1, double freq2, std::vector<double> &vector, long length) {
for (int i = 0; i < length; i++) {
double value = sin((i * 2 * M_PI * freq1) / SAMPLE_RATE) + sin((i * 2 * M_PI * freq1) / SAMPLE_RATE);
vector.push_back(value);
}
}
/// From a bitsteam, add the PCM wave bits to to the given vector
/// \param vector the vector to add the sound to
/// \param message the message to encode
void Audio::generate_afsk(std::vector<double> &vector, __1::vector<bool> &message) {
long length = static_cast<long>(round(SAMPLE_RATE * (1 / DATA_RATE)));
for (short i : message) {
if (i == 0) {
generate_tone(MARK_FREQ, vector, length);
} else {
generate_tone(SPACE_FREQ, vector, length);
}
}
}
\ No newline at end of file
//
// Created by Matthew Burket on 10/18/18.
//
#ifndef SAMEENCODER_AUDIO_H
#define SAMEENCODER_AUDIO_H
#include <vector>
class Audio {
public:
static void generate_tone(double freq, std::vector<double> &vector, long length);
static void generate_afsk(std::vector<double> &vector, std::vector<bool> &message);
static void generate_dual_tone(double freq1, double freq2, std::vector<double> &vector, long length);
};
#endif //SAMEENCODER_AUDIO_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment