diff --git a/external/rtaudio/RtAudio.cpp b/external/rtaudio/RtAudio.cpp index ddd8ff3..2167e84 100644 --- a/external/rtaudio/RtAudio.cpp +++ b/external/rtaudio/RtAudio.cpp @@ -10051,8 +10051,8 @@ void RtApi :: convertBuffer( char *outBuffer, char *inBuffer, ConvertInfo &info void RtApi :: byteSwapBuffer( char *buffer, unsigned int samples, RtAudioFormat format ) { - register char val; - register char *ptr; + char val; + char *ptr; ptr = buffer; if ( format == RTAUDIO_SINT16 ) { diff --git a/src/process/SpectrumVisualProcessor.h b/src/process/SpectrumVisualProcessor.h index 2f9f9e8..20fa627 100644 --- a/src/process/SpectrumVisualProcessor.h +++ b/src/process/SpectrumVisualProcessor.h @@ -5,6 +5,81 @@ class SpectrumVisualProcessor : public VisualProcessor { protected: virtual void process() { - + /* + std::vector *data = &input->data; + if (data && data->size()) { + if (fft_size != data->size()) { + setup(data->size()); + } + if (spectrum_points.size() < fft_size * 2) { + if (spectrum_points.capacity() < fft_size * 2) { + spectrum_points.reserve(fft_size * 2); + } + spectrum_points.resize(fft_size * 2); + } + + for (int i = 0; i < fft_size; i++) { + in[i][0] = (*data)[i].real; + in[i][1] = (*data)[i].imag; + } + + fftwf_execute(plan); + + float fft_ceil = 0, fft_floor = 1; + + if (fft_result.size() != fft_size) { + if (fft_result.capacity() < fft_size) { + fft_result.reserve(fft_size); + fft_result_ma.reserve(fft_size); + fft_result_maa.reserve(fft_size); + } + fft_result.resize(fft_size); + fft_result_ma.resize(fft_size); + fft_result_maa.resize(fft_size); + } + + int n; + for (int i = 0, iMax = fft_size / 2; i < iMax; i++) { + float a = out[i][0]; + float b = out[i][1]; + float c = sqrt(a * a + b * b); + + float x = out[fft_size / 2 + i][0]; + float y = out[fft_size / 2 + i][1]; + float z = sqrt(x * x + y * y); + + fft_result[i] = (z); + fft_result[fft_size / 2 + i] = (c); + } + + for (int i = 0, iMax = fft_size; i < iMax; i++) { + fft_result_maa[i] += (fft_result_ma[i] - fft_result_maa[i]) * 0.65; + fft_result_ma[i] += (fft_result[i] - fft_result_ma[i]) * 0.65; + + if (fft_result_maa[i] > fft_ceil) { + fft_ceil = fft_result_maa[i]; + } + if (fft_result_maa[i] < fft_floor) { + fft_floor = fft_result_maa[i]; + } + } + + fft_ceil += 1; + fft_floor -= 1; + + fft_ceil_ma = fft_ceil_ma + (fft_ceil - fft_ceil_ma) * 0.01; + fft_ceil_maa = fft_ceil_maa + (fft_ceil_ma - fft_ceil_maa) * 0.01; + + fft_floor_ma = fft_floor_ma + (fft_floor - fft_floor_ma) * 0.01; + fft_floor_maa = fft_floor_maa + (fft_floor_ma - fft_floor_maa) * 0.01; + + for (int i = 0, iMax = fft_size; i < iMax; i++) { + float v = (log10(fft_result_maa[i] - fft_floor_maa) / log10(fft_ceil_maa - fft_floor_maa)); + spectrum_points[i * 2] = ((float) i / (float) iMax); + spectrum_points[i * 2 + 1] = v; + } + + } +*/ } }; \ No newline at end of file diff --git a/src/process/WaterfallVisualProcessor.h b/src/process/WaterfallVisualProcessor.h index e1ee88f..b33c37e 100644 --- a/src/process/WaterfallVisualProcessor.h +++ b/src/process/WaterfallVisualProcessor.h @@ -6,6 +6,276 @@ class WaterfallVisualProcessor : public VisualProcessor { protected: virtual void process() { +/* + long double currentZoom = zoom; + if (mouseZoom != 1) { + currentZoom = mouseZoom; + mouseZoom = mouseZoom + (1.0 - mouseZoom) * 0.2; + if (fabs(mouseZoom-1.0)<0.01) { + mouseZoom = 1; + } + } + + long long bw; + if (currentZoom != 1) { + long long freq = wxGetApp().getFrequency(); + + if (currentZoom < 1) { + centerFreq = getCenterFrequency(); + bw = getBandwidth(); + bw = (long long) ceil((long double) bw * currentZoom); + if (bw < 100000) { + bw = 100000; + } + if (mouseTracker.mouseInView()) { + long long mfreqA = getFrequencyAt(mouseTracker.getMouseX()); + setBandwidth(bw); + long long mfreqB = getFrequencyAt(mouseTracker.getMouseX()); + centerFreq += mfreqA - mfreqB; + } + + setView(centerFreq, bw); + if (spectrumCanvas) { + spectrumCanvas->setView(centerFreq, bw); + } + } else { + if (isView) { + bw = getBandwidth(); + bw = (long long) ceil((long double) bw * currentZoom); + if (bw >= wxGetApp().getSampleRate()) { + disableView(); + if (spectrumCanvas) { + spectrumCanvas->disableView(); + } + } else { + if (mouseTracker.mouseInView()) { + long long mfreqA = getFrequencyAt(mouseTracker.getMouseX()); + setBandwidth(bw); + long long mfreqB = getFrequencyAt(mouseTracker.getMouseX()); + centerFreq += mfreqA - mfreqB; + } + + setView(getCenterFrequency(), bw); + if (spectrumCanvas) { + spectrumCanvas->setView(centerFreq, bw); + } + } + } + } + if (centerFreq < freq && (centerFreq - bandwidth / 2) < (freq - wxGetApp().getSampleRate() / 2)) { + centerFreq = (freq - wxGetApp().getSampleRate() / 2) + bandwidth / 2; + } + if (centerFreq > freq && (centerFreq + bandwidth / 2) > (freq + wxGetApp().getSampleRate() / 2)) { + centerFreq = (freq + wxGetApp().getSampleRate() / 2) - bandwidth / 2; + } + } + + std::vector *data = &input->data; + + if (data && data->size()) { + // if (fft_size != data->size() && !isView) { + // Setup(data->size(), waterfall_lines); + // } + + // if (last_bandwidth != bandwidth && !isView) { + // Setup(bandwidth, waterfall_lines); + // } + + if (spectrum_points.size() < fft_size * 2) { + spectrum_points.resize(fft_size * 2); + } + + unsigned int num_written; + + if (isView) { + if (!input->frequency || !input->sampleRate) { + return; + } + + resamplerRatio = (double) (bandwidth) / (double) input->sampleRate; + + int desired_input_size = fft_size / resamplerRatio; + + if (input->data.size() < desired_input_size) { + // std::cout << "fft underflow, desired: " << desired_input_size << " actual:" << input->data.size() << std::endl; + desired_input_size = input->data.size(); + } + + if (centerFreq != input->frequency) { + if ((centerFreq - input->frequency) != shiftFrequency || lastInputBandwidth != input->sampleRate) { + if (abs(input->frequency - centerFreq) < (wxGetApp().getSampleRate() / 2)) { + shiftFrequency = centerFreq - input->frequency; + nco_crcf_reset(freqShifter); + nco_crcf_set_frequency(freqShifter, (2.0 * M_PI) * (((double) abs(shiftFrequency)) / ((double) input->sampleRate))); + } + } + + if (shiftBuffer.size() != desired_input_size) { + if (shiftBuffer.capacity() < desired_input_size) { + shiftBuffer.reserve(desired_input_size); + } + shiftBuffer.resize(desired_input_size); + } + + if (shiftFrequency < 0) { + nco_crcf_mix_block_up(freqShifter, &input->data[0], &shiftBuffer[0], desired_input_size); + } else { + nco_crcf_mix_block_down(freqShifter, &input->data[0], &shiftBuffer[0], desired_input_size); + } + } else { + shiftBuffer.assign(input->data.begin(), input->data.end()); + } + + if (!resampler || bandwidth != lastBandwidth || lastInputBandwidth != input->sampleRate) { + float As = 60.0f; + + if (resampler) { + msresamp_crcf_destroy(resampler); + } + resampler = msresamp_crcf_create(resamplerRatio, As); + + lastBandwidth = bandwidth; + lastInputBandwidth = input->sampleRate; + } + + + int out_size = ceil((double) (desired_input_size) * resamplerRatio) + 512; + + if (resampleBuffer.size() != out_size) { + if (resampleBuffer.capacity() < out_size) { + resampleBuffer.reserve(out_size); + } + resampleBuffer.resize(out_size); + } + + + msresamp_crcf_execute(resampler, &shiftBuffer[0], desired_input_size, &resampleBuffer[0], &num_written); + + resampleBuffer.resize(fft_size); + + if (num_written < fft_size) { + for (int i = 0; i < num_written; i++) { + fft_in_data[i][0] = resampleBuffer[i].real; + fft_in_data[i][1] = resampleBuffer[i].imag; + } + for (int i = num_written; i < fft_size; i++) { + fft_in_data[i][0] = 0; + fft_in_data[i][1] = 0; + } + } else { + for (int i = 0; i < fft_size; i++) { + fft_in_data[i][0] = resampleBuffer[i].real; + fft_in_data[i][1] = resampleBuffer[i].imag; + } + } + } else { + num_written = data->size(); + if (data->size() < fft_size) { + for (int i = 0, iMax = data->size(); i < iMax; i++) { + fft_in_data[i][0] = (*data)[i].real; + fft_in_data[i][1] = (*data)[i].imag; + } + for (int i = data->size(); i < fft_size; i++) { + fft_in_data[i][0] = 0; + fft_in_data[i][1] = 0; + } + } else { + for (int i = 0; i < fft_size; i++) { + fft_in_data[i][0] = (*data)[i].real; + fft_in_data[i][1] = (*data)[i].imag; + } + } + } + + bool execute = false; + + if (num_written >= fft_size) { + execute = true; + memcpy(in, fft_in_data, fft_size * sizeof(fftwf_complex)); + memcpy(fft_last_data, in, fft_size * sizeof(fftwf_complex)); + + } else { + if (last_data_size + num_written < fft_size) { // priming + unsigned int num_copy = fft_size - last_data_size; + if (num_written > num_copy) { + num_copy = num_written; + } + memcpy(fft_last_data, fft_in_data, num_copy * sizeof(fftwf_complex)); + last_data_size += num_copy; + } else { + unsigned int num_last = (fft_size - num_written); + memcpy(in, fft_last_data + (last_data_size - num_last), num_last * sizeof(fftwf_complex)); + memcpy(in + num_last, fft_in_data, num_written * sizeof(fftwf_complex)); + memcpy(fft_last_data, in, fft_size * sizeof(fftwf_complex)); + execute = true; + } + } + + if (execute) { + fftwf_execute(plan); + + float fft_ceil = 0, fft_floor = 1; + + if (fft_result.size() < fft_size) { + fft_result.resize(fft_size); + fft_result_ma.resize(fft_size); + fft_result_maa.resize(fft_size); + } + + int n; + for (int i = 0, iMax = fft_size / 2; i < iMax; i++) { + float a = out[i][0]; + float b = out[i][1]; + float c = sqrt(a * a + b * b); + + float x = out[fft_size / 2 + i][0]; + float y = out[fft_size / 2 + i][1]; + float z = sqrt(x * x + y * y); + + fft_result[i] = (z); + fft_result[fft_size / 2 + i] = (c); + } + + for (int i = 0, iMax = fft_size; i < iMax; i++) { + if (isView) { + fft_result_maa[i] += (fft_result_ma[i] - fft_result_maa[i]) * 0.65; + fft_result_ma[i] += (fft_result[i] - fft_result_ma[i]) * 0.65; + } else { + fft_result_maa[i] += (fft_result_ma[i] - fft_result_maa[i]) * 0.65; + fft_result_ma[i] += (fft_result[i] - fft_result_ma[i]) * 0.65; + } + + if (fft_result_maa[i] > fft_ceil) { + fft_ceil = fft_result_maa[i]; + } + if (fft_result_maa[i] < fft_floor) { + fft_floor = fft_result_maa[i]; + } + } + + fft_ceil += 0.25; + fft_floor -= 1; + + fft_ceil_ma = fft_ceil_ma + (fft_ceil - fft_ceil_ma) * 0.05; + fft_ceil_maa = fft_ceil_maa + (fft_ceil_ma - fft_ceil_maa) * 0.05; + + fft_floor_ma = fft_floor_ma + (fft_floor - fft_floor_ma) * 0.05; + fft_floor_maa = fft_floor_maa + (fft_floor_ma - fft_floor_maa) * 0.05; + + for (int i = 0, iMax = fft_size; i < iMax; i++) { + float v = (log10(fft_result_maa[i] - fft_floor_maa) / log10(fft_ceil_maa - fft_floor_maa)); + spectrum_points[i * 2] = ((float) i / (float) iMax); + spectrum_points[i * 2 + 1] = v; + } + + if (spectrumCanvas) { + spectrumCanvas->spectrum_points.assign(spectrum_points.begin(), spectrum_points.end()); + spectrumCanvas->getSpectrumContext()->setCeilValue(fft_ceil_maa); + spectrumCanvas->getSpectrumContext()->setFloorValue(fft_floor_maa); + } + } + } +*/ } }; \ No newline at end of file