Skip to content

Commit

Permalink
Improved WAVE reader speed
Browse files Browse the repository at this point in the history
  • Loading branch information
markondej committed Jan 21, 2022
1 parent c41fa4e commit 245e099
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions transmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,12 +473,12 @@ void Transmitter::TransmitViaDma(WaveReader &reader, ClockOutput &output, unsign
PWMController pwm(sampleRate);
Peripherals &peripherals = Peripherals::GetInstance();

unsigned i, cbOffset = 0;
unsigned cbOffset = 0;

volatile DMAControllBlock *dmaCb = reinterpret_cast<DMAControllBlock *>(allocated.GetBaseAddress());
volatile uint32_t *clkDiv = reinterpret_cast<uint32_t *>(reinterpret_cast<uintptr_t>(dmaCb) + 2 * sizeof(DMAControllBlock) * bufferSize);
volatile uint32_t *pwmFifoData = reinterpret_cast<uint32_t *>(reinterpret_cast<uintptr_t>(clkDiv) + sizeof(uint32_t) * bufferSize);
for (i = 0; i < bufferSize; i++) {
for (unsigned i = 0; i < bufferSize; i++) {
float value = samples[i].GetMonoValue();
clkDiv[i] = CLK_PASSWORD | (0xffffff & (clockDivisor - static_cast<int32_t>(round(value * divisorRange))));
dmaCb[cbOffset].transferInfo = DMA_TI_NO_WIDE_BURST | DMA_TI_WAIT_RESP;;
Expand Down Expand Up @@ -519,7 +519,7 @@ void Transmitter::TransmitViaDma(WaveReader &reader, ClockOutput &output, unsign
}
cbOffset = 0;
eof = samples.size() < bufferSize;
for (i = 0; i < samples.size(); i++) {
for (std::size_t i = 0; i < samples.size(); i++) {
float value = samples[i].GetMonoValue();
while (i == ((dma.GetControllBlockAddress() - allocated.GetPhysicalAddress(dmaCb)) / (2 * sizeof(DMAControllBlock)))) {
std::this_thread::sleep_for(std::chrono::microseconds(BUFFER_TIME / 10));
Expand Down
1 change: 1 addition & 0 deletions wave_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ std::vector<Sample> WaveReader::GetSamples(unsigned quantity, bool &stop) {
}

std::vector<Sample> samples;
samples.reserve(quantity);
for (unsigned i = 0; i < quantity; i++) {
samples.push_back(Sample(&data[bytesPerSample * i], header.channels, header.bitsPerSample));
}
Expand Down

0 comments on commit 245e099

Please sign in to comment.