mirror of
				https://github.com/AlexandreRouma/SDRPlusPlus.git
				synced 2025-11-04 02:39:11 +01:00 
			
		
		
		
	fixing audio bug
This commit is contained in:
		@@ -1,7 +1,7 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
#include <dsp/block.h>
 | 
			
		||||
 | 
			
		||||
#define RING_BUF_SZ
 | 
			
		||||
#define RING_BUF_SZ 1000000
 | 
			
		||||
 | 
			
		||||
namespace dsp {
 | 
			
		||||
    template <class T>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,8 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
#include <dsp/block.h>
 | 
			
		||||
 | 
			
		||||
#include <spdlog/spdlog.h>
 | 
			
		||||
 | 
			
		||||
#define FAST_ATAN2_COEF1    FL_M_PI / 4.0f
 | 
			
		||||
#define FAST_ATAN2_COEF2    3.0f * FAST_ATAN2_COEF1
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,8 @@
 | 
			
		||||
#include <dsp/block.h>
 | 
			
		||||
#include <dsp/window.h>
 | 
			
		||||
 | 
			
		||||
#include <spdlog/spdlog.h>
 | 
			
		||||
 | 
			
		||||
namespace dsp {
 | 
			
		||||
 | 
			
		||||
    template <class T>
 | 
			
		||||
@@ -133,8 +135,9 @@ namespace dsp {
 | 
			
		||||
            count = _in->read();
 | 
			
		||||
            if (count < 0) { return -1; }
 | 
			
		||||
 | 
			
		||||
            if (bypass) {
 | 
			
		||||
                if (out.aquire() < 0) { return -1; } 
 | 
			
		||||
            if (bypass || true) {
 | 
			
		||||
                if (out.aquire() < 0) { return -1; }
 | 
			
		||||
                memcpy(out.data, _in->data, count * sizeof(float));
 | 
			
		||||
                _in->flush();
 | 
			
		||||
                out.write(count);
 | 
			
		||||
            }
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,8 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
#include <dsp/block.h>
 | 
			
		||||
 | 
			
		||||
#include <spdlog/spdlog.h>
 | 
			
		||||
 | 
			
		||||
namespace dsp {
 | 
			
		||||
    class FrequencyXlator : public generic_block<FrequencyXlator> {
 | 
			
		||||
    public:
 | 
			
		||||
 
 | 
			
		||||
@@ -23,19 +23,19 @@ namespace dsp {
 | 
			
		||||
            _inSampleRate = inSampleRate;
 | 
			
		||||
            _outSampleRate = outSampleRate;
 | 
			
		||||
 | 
			
		||||
            int _gcd = std::gcd((int)_inSampleRate, (int)_outSampleRate);
 | 
			
		||||
            _interp = _outSampleRate / _gcd;
 | 
			
		||||
            _decim = _inSampleRate / _gcd;
 | 
			
		||||
 | 
			
		||||
            tapCount = _window->getTapCount();
 | 
			
		||||
            taps = (float*)volk_malloc(tapCount * sizeof(float), volk_get_alignment());
 | 
			
		||||
            _window->createTaps(taps, tapCount);
 | 
			
		||||
            for (int i = 0; i < tapCount / 2; i++) {
 | 
			
		||||
                float tap = taps[tapCount - i - 1];
 | 
			
		||||
                taps[tapCount - i - 1] = taps[i];
 | 
			
		||||
                taps[i] = tap;
 | 
			
		||||
                taps[tapCount - i - 1] = taps[i] * (float)_interp;
 | 
			
		||||
                taps[i] = tap * (float)_interp;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            int _gcd = std::gcd((int)_inSampleRate, (int)_outSampleRate);
 | 
			
		||||
            _interp = _outSampleRate / _gcd;
 | 
			
		||||
            _decim = _inSampleRate / _gcd;
 | 
			
		||||
 | 
			
		||||
            buffer = (T*)volk_malloc(STREAM_BUFFER_SIZE * sizeof(T) * 2, volk_get_alignment());
 | 
			
		||||
            bufStart = &buffer[tapCount];
 | 
			
		||||
            generic_block<PolyphaseResampler<T>>::registerInput(_in);
 | 
			
		||||
@@ -80,6 +80,8 @@ namespace dsp {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        void updateWindow(dsp::filter_window::generic_window* window) {
 | 
			
		||||
            std::lock_guard<std::mutex> lck(generic_block<PolyphaseResampler<T>>::ctrlMtx);
 | 
			
		||||
            generic_block<PolyphaseResampler<T>>::tempStop();
 | 
			
		||||
            _window = window;
 | 
			
		||||
            volk_free(taps);
 | 
			
		||||
            tapCount = window->getTapCount();
 | 
			
		||||
@@ -87,9 +89,10 @@ namespace dsp {
 | 
			
		||||
            window->createTaps(taps, tapCount);
 | 
			
		||||
            for (int i = 0; i < tapCount / 2; i++) {
 | 
			
		||||
                float tap = taps[tapCount - i - 1];
 | 
			
		||||
                taps[tapCount - i - 1] = taps[i];
 | 
			
		||||
                taps[i] = tap;
 | 
			
		||||
                taps[tapCount - i - 1] = taps[i] * (float)_interp;
 | 
			
		||||
                taps[i] = tap * (float)_interp;
 | 
			
		||||
            }
 | 
			
		||||
            generic_block<PolyphaseResampler<T>>::tempStart();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int calcOutSize(int in) {
 | 
			
		||||
@@ -97,10 +100,8 @@ namespace dsp {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int run() {
 | 
			
		||||
            if constexpr (std::is_same_v<T, float>) { spdlog::warn("--------- RESAMP START --------"); }
 | 
			
		||||
            count = _in->read();
 | 
			
		||||
            if (count < 0) {
 | 
			
		||||
                if constexpr (std::is_same_v<T, float>) { spdlog::warn("--------- RESAMP STOP --------"); }
 | 
			
		||||
                return -1;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
@@ -114,16 +115,21 @@ namespace dsp {
 | 
			
		||||
                return -1;
 | 
			
		||||
            }
 | 
			
		||||
            int outIndex = 0;
 | 
			
		||||
            if constexpr (std::is_same_v<T, float>) {
 | 
			
		||||
                for (int i = 0; outIndex < outCount; i += _decim) {
 | 
			
		||||
                    out.data[outIndex] = 0;
 | 
			
		||||
                    for (int j = i % _interp; j < tapCount; j += _interp) {
 | 
			
		||||
                        out.data[outIndex] += buffer[((i - j) / _interp) + tapCount] * taps[j];
 | 
			
		||||
                    }
 | 
			
		||||
                    outIndex++;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            // if constexpr (std::is_same_v<T, float>) {
 | 
			
		||||
            //     // for (int i = 0; outIndex < outCount; i += _decim) {
 | 
			
		||||
            //     //     out.data[outIndex] = 0;
 | 
			
		||||
            //     //     for (int j = i % _interp; j < tapCount; j += _interp) {
 | 
			
		||||
            //     //         out.data[outIndex] += buffer[((i - j) / _interp) + tapCount] * taps[j];
 | 
			
		||||
            //     //     }
 | 
			
		||||
            //     //     outIndex++;
 | 
			
		||||
            //     // }
 | 
			
		||||
            //     for (int i = 0; i < outCount; i++) {
 | 
			
		||||
            //         out.data[i] = 1.0f;
 | 
			
		||||
            //     }
 | 
			
		||||
            // }
 | 
			
		||||
            if constexpr (std::is_same_v<T, complex_t>) {
 | 
			
		||||
                static_assert(std::is_same_v<T, complex_t>);
 | 
			
		||||
                spdlog::warn("{0}", outCount);
 | 
			
		||||
                for (int i = 0; outIndex < outCount; i += _decim) {
 | 
			
		||||
                    out.data[outIndex].i = 0;
 | 
			
		||||
                    out.data[outIndex].q = 0;
 | 
			
		||||
@@ -134,7 +140,7 @@ namespace dsp {
 | 
			
		||||
                    outIndex++;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            out.write(count);
 | 
			
		||||
            out.write(outCount);
 | 
			
		||||
 | 
			
		||||
            memmove(buffer, &buffer[count], tapCount * sizeof(T));
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,7 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
#include <dsp/block.h>
 | 
			
		||||
#include <cstring>
 | 
			
		||||
#include <spdlog/spdlog.h>
 | 
			
		||||
 | 
			
		||||
namespace dsp {
 | 
			
		||||
    template <class T>
 | 
			
		||||
 
 | 
			
		||||
@@ -63,6 +63,7 @@ namespace dsp {
 | 
			
		||||
 | 
			
		||||
        void init(stream<T>* in) {
 | 
			
		||||
            _in = in;
 | 
			
		||||
            data.init(480); // TODO: Use an argument
 | 
			
		||||
            generic_block<RingBufferSink<T>>::registerInput(_in);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -28,62 +28,17 @@ namespace io {
 | 
			
		||||
            
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        AudioSink(int bufferSize) {
 | 
			
		||||
            _bufferSize = bufferSize;
 | 
			
		||||
            monoBuffer = new float[_bufferSize];
 | 
			
		||||
            stereoBuffer = new dsp::stereo_t[_bufferSize];
 | 
			
		||||
            _volume = 1.0f;
 | 
			
		||||
            Pa_Initialize();
 | 
			
		||||
 | 
			
		||||
            devTxtList = "";
 | 
			
		||||
            int devCount = Pa_GetDeviceCount();
 | 
			
		||||
            devIndex = Pa_GetDefaultOutputDevice();
 | 
			
		||||
            const PaDeviceInfo *deviceInfo;
 | 
			
		||||
            PaStreamParameters outputParams;
 | 
			
		||||
            outputParams.sampleFormat = paFloat32;
 | 
			
		||||
            outputParams.hostApiSpecificStreamInfo = NULL;
 | 
			
		||||
            for(int i = 0; i < devCount; i++) {
 | 
			
		||||
                deviceInfo = Pa_GetDeviceInfo(i);
 | 
			
		||||
                if (deviceInfo->maxOutputChannels < 1) {
 | 
			
		||||
                    continue;
 | 
			
		||||
                }
 | 
			
		||||
                AudioDevice_t dev;
 | 
			
		||||
                dev.name = deviceInfo->name;
 | 
			
		||||
                dev.index = i;
 | 
			
		||||
                dev.channels = std::min<int>(deviceInfo->maxOutputChannels, 2);
 | 
			
		||||
                dev.sampleRates.clear();
 | 
			
		||||
                dev.txtSampleRates = "";
 | 
			
		||||
                for (int j = 0; j < 6; j++) {
 | 
			
		||||
                    outputParams.channelCount = dev.channels;
 | 
			
		||||
                    outputParams.device = dev.index;
 | 
			
		||||
                    outputParams.suggestedLatency = deviceInfo->defaultLowOutputLatency;
 | 
			
		||||
                    PaError err = Pa_IsFormatSupported(NULL, &outputParams, POSSIBLE_SAMP_RATE[j]);
 | 
			
		||||
                    if (err != paFormatIsSupported) {
 | 
			
		||||
                        continue;
 | 
			
		||||
                    }
 | 
			
		||||
                    dev.sampleRates.push_back(POSSIBLE_SAMP_RATE[j]);
 | 
			
		||||
                    dev.txtSampleRates += std::to_string((int)POSSIBLE_SAMP_RATE[j]);
 | 
			
		||||
                    dev.txtSampleRates += '\0';
 | 
			
		||||
                }
 | 
			
		||||
                if (dev.sampleRates.size() == 0) {
 | 
			
		||||
                    continue;
 | 
			
		||||
                }
 | 
			
		||||
                if (i == devIndex) {
 | 
			
		||||
                    devListIndex = devices.size();
 | 
			
		||||
                    defaultDev = devListIndex;
 | 
			
		||||
                }
 | 
			
		||||
                devices.push_back(dev);
 | 
			
		||||
                deviceNames.push_back(deviceInfo->name);
 | 
			
		||||
                devTxtList += deviceInfo->name;
 | 
			
		||||
                devTxtList += '\0';
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        AudioSink(int bufferSize) { init(bufferSize); }
 | 
			
		||||
 | 
			
		||||
        void init(int bufferSize) {
 | 
			
		||||
            _bufferSize = bufferSize;
 | 
			
		||||
            monoBuffer = new float[_bufferSize];
 | 
			
		||||
            stereoBuffer = new dsp::stereo_t[_bufferSize];
 | 
			
		||||
            _volume = 1.0f;
 | 
			
		||||
 | 
			
		||||
            monoSink.init(&monoDummy);
 | 
			
		||||
            stereoSink.init(&stereoDummy);
 | 
			
		||||
 | 
			
		||||
            Pa_Initialize();
 | 
			
		||||
 | 
			
		||||
            devTxtList = "";
 | 
			
		||||
@@ -343,6 +298,8 @@ namespace io {
 | 
			
		||||
        int defaultDev;
 | 
			
		||||
        double _sampleRate;
 | 
			
		||||
        int _bufferSize;
 | 
			
		||||
        dsp::stream<float> monoDummy;
 | 
			
		||||
        dsp::stream<dsp::stereo_t> stereoDummy;
 | 
			
		||||
        dsp::RingBufferSink<float> monoSink;
 | 
			
		||||
        dsp::RingBufferSink<dsp::stereo_t> stereoSink;
 | 
			
		||||
        float* monoBuffer;
 | 
			
		||||
 
 | 
			
		||||
@@ -286,5 +286,6 @@ void SigPath::start() {
 | 
			
		||||
    demod.start();
 | 
			
		||||
    audioResamp.start();
 | 
			
		||||
    deemp.start();
 | 
			
		||||
    //ns.start();
 | 
			
		||||
    audio::startStream(vfoName);
 | 
			
		||||
}
 | 
			
		||||
@@ -63,6 +63,8 @@ private:
 | 
			
		||||
    dsp::filter_window::BlackmanWindow audioWin;
 | 
			
		||||
    dsp::PolyphaseResampler<float> audioResamp;
 | 
			
		||||
 | 
			
		||||
    dsp::NullSink<float> ns;
 | 
			
		||||
 | 
			
		||||
    std::string vfoName;
 | 
			
		||||
 | 
			
		||||
    float sampleRate;
 | 
			
		||||
 
 | 
			
		||||
@@ -3,7 +3,7 @@
 | 
			
		||||
        "Radio": {
 | 
			
		||||
            "device": "default",
 | 
			
		||||
            "sampleRate": 48000.0,
 | 
			
		||||
            "volume": 0.0
 | 
			
		||||
            "volume": 1.0
 | 
			
		||||
        },
 | 
			
		||||
        "Radio 1": {
 | 
			
		||||
            "device": "Speakers (Realtek High Definition Audio)",
 | 
			
		||||
@@ -18,7 +18,7 @@
 | 
			
		||||
    },
 | 
			
		||||
    "bandPlan": "General",
 | 
			
		||||
    "bandPlanEnabled": true,
 | 
			
		||||
    "fftHeight": 298,
 | 
			
		||||
    "fftHeight": 296,
 | 
			
		||||
    "frequency": 99000000,
 | 
			
		||||
    "max": 0.0,
 | 
			
		||||
    "maximized": false,
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								root_dev/recordings/audio_19-16-25_02-11-2020.wav
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								root_dev/recordings/audio_19-16-25_02-11-2020.wav
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								root_dev/recordings/audio_20-21-27_02-11-2020.wav
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								root_dev/recordings/audio_20-21-27_02-11-2020.wav
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								root_dev/recordings/audio_20-21-55_02-11-2020.wav
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								root_dev/recordings/audio_20-21-55_02-11-2020.wav
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								root_dev/recordings/baseband_20-21-19_02-11-2020.wav
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								root_dev/recordings/baseband_20-21-19_02-11-2020.wav
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
		Reference in New Issue
	
	Block a user