kopia lustrzana https://github.com/markondej/fm_transmitter
Thread params are now passed as vectors
rodzic
36bbc5cd3b
commit
9043b7d14a
|
@ -64,7 +64,7 @@
|
|||
"transmitter.h"
|
||||
<cstdlib>
|
||||
|
||||
1438084671 /home/marcin/Repozytoria/fm_transmitter/transmitter.h
|
||||
1438167987 /home/marcin/Repozytoria/fm_transmitter/transmitter.h
|
||||
"wave_reader.h"
|
||||
"stdin_reader.h"
|
||||
"error_reporter.h"
|
||||
|
@ -79,7 +79,7 @@
|
|||
|
||||
1438083081 /home/marcin/Repozytoria/fm_transmitter/pcm_wave_header.h
|
||||
|
||||
1438084940 source:/home/marcin/Repozytoria/fm_transmitter/transmitter.cpp
|
||||
1438185774 source:/home/marcin/Repozytoria/fm_transmitter/transmitter.cpp
|
||||
"transmitter.h"
|
||||
<exception>
|
||||
<sstream>
|
||||
|
@ -245,13 +245,13 @@
|
|||
<unistd.h>
|
||||
<iostream>
|
||||
|
||||
1438091088 /home/marcin/Repozytoria/fm_transmitter/stdin_reader.h
|
||||
1438185129 /home/marcin/Repozytoria/fm_transmitter/stdin_reader.h
|
||||
<vector>
|
||||
<fcntl.h>
|
||||
"audio_format.h"
|
||||
"error_reporter.h"
|
||||
|
||||
1438085397 source:/home/marcin/Repozytoria/fm_transmitter/stdin_reader.cpp
|
||||
1438185748 source:/home/marcin/Repozytoria/fm_transmitter/stdin_reader.cpp
|
||||
"stdin_reader.h"
|
||||
<exception>
|
||||
<sstream>
|
||||
|
|
|
@ -43,21 +43,25 @@ StdinReader::StdinReader()
|
|||
{
|
||||
ostringstream oss;
|
||||
|
||||
doStop = false;
|
||||
doStop = true;
|
||||
isPreparingFrames = false;
|
||||
isReading = false;
|
||||
|
||||
void *params[4];
|
||||
params[0] = &buffer;
|
||||
params[1] = &doStop;
|
||||
params[2] = &isPreparingFrames;
|
||||
params[3] = &isReading;
|
||||
vector<void*> params;
|
||||
params.push_back((void*)&buffer);
|
||||
params.push_back((void*)&doStop);
|
||||
params.push_back((void*)&isPreparingFrames);
|
||||
params.push_back((void*)&isReading);
|
||||
|
||||
int returnCode = pthread_create(&thread, NULL, &StdinReader::readStdin, (void*)params);
|
||||
int returnCode = pthread_create(&thread, NULL, &StdinReader::readStdin, (void*)¶ms);
|
||||
if (returnCode) {
|
||||
oss << "Cannot create new thread (code: " << returnCode << ")";
|
||||
errorMessage = oss.str();
|
||||
throw exception();
|
||||
}
|
||||
|
||||
while (doStop) {
|
||||
usleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,22 +79,29 @@ StdinReader *StdinReader::getInstance()
|
|||
|
||||
void StdinReader::readStdin(void *params)
|
||||
{
|
||||
vector<char> *buffer = ((vector<char>**)params)[0];
|
||||
bool *doStop = ((bool**)params)[1];
|
||||
bool *isPreparingFrames = ((bool**)params)[2];
|
||||
bool *isReading = ((bool**)params)[3];
|
||||
vector<char> *buffer = (vector<char>*)(*((vector<void*>*)params))[0];
|
||||
bool *doStop = (bool*)(*((vector<void*>*)params))[1];
|
||||
bool *isPreparingFrames = (bool*)(*((vector<void*>*)params))[2];
|
||||
bool *isReading = (bool*)(*((vector<void*>*)params))[3];
|
||||
|
||||
*doStop = false;
|
||||
char *readBuffer = new char[BUFFER_SIZE];
|
||||
while(!*doStop) {
|
||||
*isReading = true;
|
||||
|
||||
while (*isPreparingFrames) {
|
||||
usleep(1);
|
||||
}
|
||||
*isReading = true;
|
||||
|
||||
int bytes = read(STDIN_FILENO, readBuffer, BUFFER_SIZE);
|
||||
buffer->insert(buffer->end(), readBuffer, readBuffer + bytes);
|
||||
usleep(1);
|
||||
|
||||
*isReading = false;
|
||||
usleep(1);
|
||||
|
||||
}
|
||||
|
||||
delete readBuffer;
|
||||
}
|
||||
|
||||
vector<float> *StdinReader::getFrames(unsigned int frameCount)
|
||||
|
@ -103,7 +114,7 @@ vector<float> *StdinReader::getFrames(unsigned int frameCount)
|
|||
}
|
||||
isPreparingFrames = true;
|
||||
|
||||
bufferSize = buffer.size();
|
||||
bufferSize = 0;
|
||||
bytesPerFrame = (BITS_PER_SAMPLE >> 3) * CHANNELS;
|
||||
bytesToRead = frameCount * bytesPerFrame;
|
||||
restBytes = bufferSize % bytesPerFrame;
|
||||
|
|
|
@ -40,7 +40,6 @@
|
|||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
|
||||
using std::exception;
|
||||
using std::ostringstream;
|
||||
|
||||
|
@ -119,14 +118,14 @@ void Transmitter::play()
|
|||
|
||||
buffer = (!readStdin) ? waveReader->getFrames(bufferFrames, frameOffset) : stdinReader->getFrames(bufferFrames);
|
||||
|
||||
void *params[5];
|
||||
params[0] = &format.sampleRate;
|
||||
params[1] = &clockDivisor;
|
||||
params[2] = &frameOffset;
|
||||
params[3] = &buffer;
|
||||
params[4] = peripherals;
|
||||
vector<void*> params;
|
||||
params.push_back((void*)&format.sampleRate);
|
||||
params.push_back((void*)&clockDivisor);
|
||||
params.push_back((void*)&frameOffset);
|
||||
params.push_back((void*)&buffer);
|
||||
params.push_back((void*)peripherals);
|
||||
|
||||
int returnCode = pthread_create(&thread, NULL, &Transmitter::transmit, (void*)params);
|
||||
int returnCode = pthread_create(&thread, NULL, &Transmitter::transmit, (void*)¶ms);
|
||||
if (returnCode) {
|
||||
oss << "Cannot create new thread (code: " << returnCode << ")";
|
||||
errorMessage = oss.str();
|
||||
|
@ -153,11 +152,11 @@ void Transmitter::transmit(void *params)
|
|||
vector<float> *frames = NULL;
|
||||
float *data;
|
||||
|
||||
unsigned int *sampleRate = ((unsigned int**)params)[0];
|
||||
unsigned int *clockDivisor = ((unsigned int**)params)[1];
|
||||
unsigned int *frameOffset = ((unsigned int**)params)[2];
|
||||
vector<float> **buffer = ((vector<float>***)params)[3];
|
||||
volatile unsigned *peripherals = ((volatile unsigned**)params)[4];
|
||||
unsigned int *sampleRate = (unsigned int*)(*((vector<void*>*)params))[0];
|
||||
unsigned int *clockDivisor = (unsigned int*)(*((vector<void*>*)params))[1];
|
||||
unsigned int *frameOffset = (unsigned int*)(*((vector<void*>*)params))[2];
|
||||
vector<float> **buffer = (vector<float>**)(*((vector<void*>*)params))[3];
|
||||
volatile unsigned *peripherals = (volatile unsigned*)(*((vector<void*>*)params))[4];
|
||||
|
||||
ACCESS(peripherals, 0x00200000) = (ACCESS(peripherals, 0x00200000) & 0xFFFF8FFF) | (0x01 << 14);
|
||||
ACCESS(peripherals, 0x00101070) = (0x5A << 24) | (0x01 << 9) | (0x01 << 4) | 0x06;
|
||||
|
@ -186,19 +185,15 @@ void Transmitter::transmit(void *params)
|
|||
offset -= length;
|
||||
break;
|
||||
}
|
||||
|
||||
ACCESS(peripherals, 0x00101074) = (0x5A << 24) | ((*clockDivisor) - (int)(round(data[offset] * 16.0)));
|
||||
|
||||
while (temp >= offset) {
|
||||
usleep(1);
|
||||
|
||||
current = ACCESS64(peripherals, 0x00003004);
|
||||
offset = (current - start) * (*sampleRate) / 1000000;
|
||||
}
|
||||
}
|
||||
|
||||
start = ACCESS64(peripherals, 0x00003004);
|
||||
|
||||
delete frames;
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue