kopia lustrzana https://github.com/markondej/fm_transmitter
Removed bad preemphasis filter
commit
7254ce8b67
16
sample.cpp
16
sample.cpp
|
@ -55,18 +55,4 @@ Sample::Sample(uint8_t *data, uint16_t channels, uint16_t bitsPerChannel)
|
||||||
float Sample::getMonoValue() const
|
float Sample::getMonoValue() const
|
||||||
{
|
{
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NO_PREEMP
|
|
||||||
PreEmphasis::PreEmphasis(uint32_t sampleRate)
|
|
||||||
: timeConst(sampleRate * 75.0e-6f), prevValue(0.f)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
float PreEmphasis::filter(float value)
|
|
||||||
{
|
|
||||||
value = value + (prevValue - value) / (1.f - timeConst);
|
|
||||||
prevValue = value;
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
#endif
|
|
11
sample.hpp
11
sample.hpp
|
@ -45,15 +45,4 @@ class Sample
|
||||||
float value;
|
float value;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef NO_PREEMP
|
|
||||||
class PreEmphasis
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
PreEmphasis(uint32_t sampleRate);
|
|
||||||
float filter(float value);
|
|
||||||
protected:
|
|
||||||
float timeConst, prevValue;
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // SAMPLE_HPP
|
#endif // SAMPLE_HPP
|
||||||
|
|
|
@ -174,7 +174,7 @@ uint32_t Transmitter::getPeripheralPhysAddress(volatile void *object) const
|
||||||
return PERIPHERALS_PHYS_BASE + (reinterpret_cast<uint32_t>(object) - reinterpret_cast<uint32_t>(peripherals));
|
return PERIPHERALS_PHYS_BASE + (reinterpret_cast<uint32_t>(object) - reinterpret_cast<uint32_t>(peripherals));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Transmitter::getPeripheralVirtAddress(uint32_t offset) const
|
uint32_t Transmitter::getPeripheralVirtAddress(uint32_t offset)
|
||||||
{
|
{
|
||||||
return reinterpret_cast<uint32_t>(peripherals) + offset;
|
return reinterpret_cast<uint32_t>(peripherals) + offset;
|
||||||
}
|
}
|
||||||
|
@ -379,18 +379,12 @@ void Transmitter::transmitViaDma(WaveReader &reader, uint32_t bufferSize, uint8_
|
||||||
volatile PWMRegisters *pwm = initPwmController();
|
volatile PWMRegisters *pwm = initPwmController();
|
||||||
|
|
||||||
uint32_t i, cbOffset = 0;
|
uint32_t i, cbOffset = 0;
|
||||||
#ifndef NO_PREEMP
|
|
||||||
PreEmphasis preEmphasis(sampleRate);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
volatile DMAControllBlock *dmaCb = reinterpret_cast<DMAControllBlock *>(dmaMemory.virtualBase);
|
volatile DMAControllBlock *dmaCb = reinterpret_cast<DMAControllBlock *>(dmaMemory.virtualBase);
|
||||||
volatile uint32_t *clkDiv = reinterpret_cast<uint32_t *>(reinterpret_cast<uint32_t>(dmaCb) + 2 * sizeof(DMAControllBlock) * bufferSize);
|
volatile uint32_t *clkDiv = reinterpret_cast<uint32_t *>(reinterpret_cast<uint32_t>(dmaCb) + 2 * sizeof(DMAControllBlock) * bufferSize);
|
||||||
volatile uint32_t *pwmFifoData = reinterpret_cast<uint32_t *>(reinterpret_cast<uint32_t>(clkDiv) + sizeof(uint32_t) * bufferSize);
|
volatile uint32_t *pwmFifoData = reinterpret_cast<uint32_t *>(reinterpret_cast<uint32_t>(clkDiv) + sizeof(uint32_t) * bufferSize);
|
||||||
for (i = 0; i < bufferSize; i++) {
|
for (i = 0; i < bufferSize; i++) {
|
||||||
float value = samples[i].getMonoValue();
|
float value = samples[i].getMonoValue();
|
||||||
#ifndef NO_PREEMP
|
|
||||||
value = preEmphasis.filter(value);
|
|
||||||
#endif
|
|
||||||
clkDiv[i] = (0x5A << 24) | (clockDivisor - static_cast<int32_t>(round(value * divisorRange)));
|
clkDiv[i] = (0x5A << 24) | (clockDivisor - static_cast<int32_t>(round(value * divisorRange)));
|
||||||
dmaCb[cbOffset].transferInfo = (0x01 << 26) | (0x01 << 3);
|
dmaCb[cbOffset].transferInfo = (0x01 << 26) | (0x01 << 3);
|
||||||
dmaCb[cbOffset].srcAddress = getMemoryPhysAddress(dmaMemory, &clkDiv[i]);
|
dmaCb[cbOffset].srcAddress = getMemoryPhysAddress(dmaMemory, &clkDiv[i]);
|
||||||
|
@ -437,9 +431,6 @@ void Transmitter::transmitViaDma(WaveReader &reader, uint32_t bufferSize, uint8_
|
||||||
eof = samples.size() < bufferSize;
|
eof = samples.size() < bufferSize;
|
||||||
for (i = 0; i < samples.size(); i++) {
|
for (i = 0; i < samples.size(); i++) {
|
||||||
float value = samples[i].getMonoValue();
|
float value = samples[i].getMonoValue();
|
||||||
#ifndef NO_PREEMP
|
|
||||||
value = preEmphasis.filter(value);
|
|
||||||
#endif
|
|
||||||
while (i == ((dma->cbAddress - getMemoryPhysAddress(dmaMemory, dmaCb)) / (2 * sizeof(DMAControllBlock)))) {
|
while (i == ((dma->cbAddress - getMemoryPhysAddress(dmaMemory, dmaCb)) / (2 * sizeof(DMAControllBlock)))) {
|
||||||
std::this_thread::sleep_for(std::chrono::microseconds(1000));
|
std::this_thread::sleep_for(std::chrono::microseconds(1000));
|
||||||
}
|
}
|
||||||
|
@ -456,10 +447,6 @@ void Transmitter::transmitViaDma(WaveReader &reader, uint32_t bufferSize, uint8_
|
||||||
|
|
||||||
void Transmitter::transmitThread()
|
void Transmitter::transmitThread()
|
||||||
{
|
{
|
||||||
#ifndef NO_PREEMP
|
|
||||||
PreEmphasis preEmphasis(sampleRate);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
volatile TimerRegisters *timer = reinterpret_cast<TimerRegisters *>(getPeripheralVirtAddress(TIMER_BASE_OFFSET));
|
volatile TimerRegisters *timer = reinterpret_cast<TimerRegisters *>(getPeripheralVirtAddress(TIMER_BASE_OFFSET));
|
||||||
uint64_t current = *(reinterpret_cast<volatile uint64_t *>(&timer->low));
|
uint64_t current = *(reinterpret_cast<volatile uint64_t *>(&timer->low));
|
||||||
uint64_t playbackStart = current;
|
uint64_t playbackStart = current;
|
||||||
|
@ -483,7 +470,7 @@ void Transmitter::transmitThread()
|
||||||
unlock();
|
unlock();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
std::vector<Sample> loaded(std::move(samples));
|
std::vector<Sample> loaded = std::move(samples);
|
||||||
unlock();
|
unlock();
|
||||||
|
|
||||||
sampleOffset = (current - playbackStart) * sampleRate / 1000000;
|
sampleOffset = (current - playbackStart) * sampleRate / 1000000;
|
||||||
|
@ -495,9 +482,6 @@ void Transmitter::transmitThread()
|
||||||
}
|
}
|
||||||
uint32_t prevOffset = offset;
|
uint32_t prevOffset = offset;
|
||||||
float value = loaded[offset].getMonoValue();
|
float value = loaded[offset].getMonoValue();
|
||||||
#ifndef NO_PREEMP
|
|
||||||
value = preEmphasis.filter(value);
|
|
||||||
#endif
|
|
||||||
output->div = (0x5A << 24) | (clockDivisor - static_cast<int32_t>(round(value * divisorRange)));
|
output->div = (0x5A << 24) | (clockDivisor - static_cast<int32_t>(round(value * divisorRange)));
|
||||||
while (offset == prevOffset) {
|
while (offset == prevOffset) {
|
||||||
std::this_thread::sleep_for(std::chrono::microseconds(1)); // asm("nop");
|
std::this_thread::sleep_for(std::chrono::microseconds(1)); // asm("nop");
|
||||||
|
|
|
@ -46,7 +46,7 @@ struct ClockRegisters;
|
||||||
class Transmitter
|
class Transmitter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~Transmitter();
|
~Transmitter();
|
||||||
Transmitter(const Transmitter &) = delete;
|
Transmitter(const Transmitter &) = delete;
|
||||||
Transmitter(Transmitter &&) = delete;
|
Transmitter(Transmitter &&) = delete;
|
||||||
Transmitter &operator=(const Transmitter &) = delete;
|
Transmitter &operator=(const Transmitter &) = delete;
|
||||||
|
@ -59,7 +59,7 @@ class Transmitter
|
||||||
uint32_t getPeripheralsSize() const;
|
uint32_t getPeripheralsSize() const;
|
||||||
float getSourceFreq() const;
|
float getSourceFreq() const;
|
||||||
uint32_t getPeripheralPhysAddress(volatile void *object) const;
|
uint32_t getPeripheralPhysAddress(volatile void *object) const;
|
||||||
static uint32_t getPeripheralVirtAddress(uint32_t offset) const;
|
static uint32_t getPeripheralVirtAddress(uint32_t offset);
|
||||||
uint32_t getMemoryPhysAddress(AllocatedMemory &memory, volatile void *object) const;
|
uint32_t getMemoryPhysAddress(AllocatedMemory &memory, volatile void *object) const;
|
||||||
AllocatedMemory allocateMemory(uint32_t size);
|
AllocatedMemory allocateMemory(uint32_t size);
|
||||||
void freeMemory(AllocatedMemory &memory);
|
void freeMemory(AllocatedMemory &memory);
|
||||||
|
|
|
@ -144,7 +144,7 @@ std::vector<Sample> WaveReader::getSamples(uint32_t quantity, bool &continueFlag
|
||||||
quantity = bytesToRead / bytesPerSample;
|
quantity = bytesToRead / bytesPerSample;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<uint8_t> data(std::move(readData(bytesToRead, false, continueFlag)));
|
std::vector<uint8_t> data = std::move(readData(bytesToRead, false, continueFlag));
|
||||||
if (data.size() < bytesToRead) {
|
if (data.size() < bytesToRead) {
|
||||||
quantity = data.size() / bytesPerSample;
|
quantity = data.size() / bytesPerSample;
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue