Removed bad preemphasis filter

pull/103/head
Marcin Kondej 2019-12-19 03:49:18 +01:00
commit 7254ce8b67
5 zmienionych plików z 6 dodań i 47 usunięć

Wyświetl plik

@ -55,18 +55,4 @@ Sample::Sample(uint8_t *data, uint16_t channels, uint16_t bitsPerChannel)
float Sample::getMonoValue() const
{
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
}

Wyświetl plik

@ -45,15 +45,4 @@ class Sample
float value;
};
#ifndef NO_PREEMP
class PreEmphasis
{
public:
PreEmphasis(uint32_t sampleRate);
float filter(float value);
protected:
float timeConst, prevValue;
};
#endif
#endif // SAMPLE_HPP

Wyświetl plik

@ -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));
}
uint32_t Transmitter::getPeripheralVirtAddress(uint32_t offset) const
uint32_t Transmitter::getPeripheralVirtAddress(uint32_t 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();
uint32_t i, cbOffset = 0;
#ifndef NO_PREEMP
PreEmphasis preEmphasis(sampleRate);
#endif
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 *pwmFifoData = reinterpret_cast<uint32_t *>(reinterpret_cast<uint32_t>(clkDiv) + sizeof(uint32_t) * bufferSize);
for (i = 0; i < bufferSize; i++) {
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)));
dmaCb[cbOffset].transferInfo = (0x01 << 26) | (0x01 << 3);
dmaCb[cbOffset].srcAddress = getMemoryPhysAddress(dmaMemory, &clkDiv[i]);
@ -437,9 +431,6 @@ void Transmitter::transmitViaDma(WaveReader &reader, uint32_t bufferSize, uint8_
eof = samples.size() < bufferSize;
for (i = 0; i < samples.size(); i++) {
float value = samples[i].getMonoValue();
#ifndef NO_PREEMP
value = preEmphasis.filter(value);
#endif
while (i == ((dma->cbAddress - getMemoryPhysAddress(dmaMemory, dmaCb)) / (2 * sizeof(DMAControllBlock)))) {
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()
{
#ifndef NO_PREEMP
PreEmphasis preEmphasis(sampleRate);
#endif
volatile TimerRegisters *timer = reinterpret_cast<TimerRegisters *>(getPeripheralVirtAddress(TIMER_BASE_OFFSET));
uint64_t current = *(reinterpret_cast<volatile uint64_t *>(&timer->low));
uint64_t playbackStart = current;
@ -483,7 +470,7 @@ void Transmitter::transmitThread()
unlock();
break;
}
std::vector<Sample> loaded(std::move(samples));
std::vector<Sample> loaded = std::move(samples);
unlock();
sampleOffset = (current - playbackStart) * sampleRate / 1000000;
@ -495,9 +482,6 @@ void Transmitter::transmitThread()
}
uint32_t prevOffset = offset;
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)));
while (offset == prevOffset) {
std::this_thread::sleep_for(std::chrono::microseconds(1)); // asm("nop");

Wyświetl plik

@ -46,7 +46,7 @@ struct ClockRegisters;
class Transmitter
{
public:
virtual ~Transmitter();
~Transmitter();
Transmitter(const Transmitter &) = delete;
Transmitter(Transmitter &&) = delete;
Transmitter &operator=(const Transmitter &) = delete;
@ -59,7 +59,7 @@ class Transmitter
uint32_t getPeripheralsSize() const;
float getSourceFreq() 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;
AllocatedMemory allocateMemory(uint32_t size);
void freeMemory(AllocatedMemory &memory);

Wyświetl plik

@ -144,7 +144,7 @@ std::vector<Sample> WaveReader::getSamples(uint32_t quantity, bool &continueFlag
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) {
quantity = data.size() / bytesPerSample;
}