mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 10:04:33 +02:00
resampler working with pipe tests, but not virtual sound card
This commit is contained in:
parent
a04cfa62f3
commit
64b7582913
2
.github/workflows/ctest.yml
vendored
2
.github/workflows/ctest.yml
vendored
|
@ -17,7 +17,7 @@ jobs:
|
|||
shell: bash
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install octave octave-common octave-signal sox python3 python3-pip portaudio19-dev python3-pyaudio alsa-utils
|
||||
sudo apt-get install octave octave-common octave-signal sox python3 python3-pip portaudio19-dev python3-pyaudio
|
||||
pip3 install psutil crcengine ujson pyserial numpy structlog miniaudio
|
||||
|
||||
- name: Build codec2
|
||||
|
|
|
@ -33,6 +33,7 @@ add_test(NAME 001_highsnr_stdio_P_C_SM
|
|||
PATH=$PATH:${CODEC2_BUILD_DIR}/src;
|
||||
cd ${CMAKE_CURRENT_SOURCE_DIR}/test/001_highsnr_stdio_audio;
|
||||
python3 test_tx.py --mode datac0 --delay 500 --framesperburst ${FRAMESPERBURST} --bursts ${BURSTS} |
|
||||
sox -t .s16 -r 48000 -c 1 - -t .s16 -r 8000 -c 1 - |
|
||||
freedv_data_raw_rx datac0 - - --framesperburst ${FRAMESPERBURST} | hexdump -C")
|
||||
set_tests_properties(001_highsnr_stdio_P_C_SM PROPERTIES PASS_REGULAR_EXPRESSION "HELLO WORLD")
|
||||
|
||||
|
@ -41,6 +42,7 @@ add_test(NAME 001_highsnr_stdio_C_P_SM
|
|||
PATH=$PATH:${CODEC2_BUILD_DIR}/src;
|
||||
cd ${CMAKE_CURRENT_SOURCE_DIR}/test/001_highsnr_stdio_audio;
|
||||
freedv_data_raw_tx datac0 --testframes ${TESTFRAMES} --bursts ${BURSTS} --framesperburst ${FRAMESPERBURST} /dev/zero - |
|
||||
sox -t .s16 -r 8000 -c 1 - -t .s16 -r 48000 -c 1 - |
|
||||
python3 test_rx.py --mode datac0 --framesperburst ${FRAMESPERBURST} --bursts ${BURSTS}")
|
||||
set_tests_properties(001_highsnr_stdio_C_P_SM PROPERTIES PASS_REGULAR_EXPRESSION "RECEIVED BURSTS: ${BURSTS} RECEIVED FRAMES: ${FRAMESPERBURST}")
|
||||
|
||||
|
|
|
@ -105,7 +105,7 @@ timeout = time.time() + TIMEOUT
|
|||
receive = True
|
||||
audio_buffer = codec2.audio_buffer(codec2.api.freedv_get_n_max_modem_samples(freedv))
|
||||
AUDIO_FRAMES_PER_BUFFER_8K = int(AUDIO_FRAMES_PER_BUFFER/codec2.api.FDMDV_OS_48)
|
||||
resampler = codec2.resampler(AUDIO_FRAMES_PER_BUFFER,AUDIO_FRAMES_PER_BUFFER_8K)
|
||||
resampler = codec2.resampler()
|
||||
|
||||
# initial number of samples we need
|
||||
nin = codec2.api.freedv_nin(freedv)
|
||||
|
@ -120,8 +120,8 @@ while receive and time.time() < timeout:
|
|||
# insert samples in buffer
|
||||
x = np.frombuffer(data_in48k, dtype=np.int16)
|
||||
if len(x) != AUDIO_FRAMES_PER_BUFFER:
|
||||
break
|
||||
x = resampler.resample48_to_8(x)
|
||||
receive = False
|
||||
x = resampler.resample48_to_8(x)
|
||||
audio_buffer.push(x)
|
||||
|
||||
# when we have enough samples call FreeDV Rx
|
||||
|
|
|
@ -11,7 +11,7 @@ import argparse
|
|||
import sys
|
||||
sys.path.insert(0,'..')
|
||||
import codec2
|
||||
|
||||
import numpy as np
|
||||
|
||||
# GET PARAMETER INPUTS
|
||||
parser = argparse.ArgumentParser(description='Simons TEST TNC')
|
||||
|
@ -39,11 +39,10 @@ AUDIO_OUTPUT_DEVICE = args.AUDIO_OUTPUT_DEVICE
|
|||
|
||||
MODE = codec2.FREEDV_MODE[args.FREEDV_MODE].value
|
||||
|
||||
|
||||
# AUDIO PARAMETERS
|
||||
AUDIO_FRAMES_PER_BUFFER = 2048
|
||||
AUDIO_FRAMES_PER_BUFFER = 2400
|
||||
MODEM_SAMPLE_RATE = codec2.api.FREEDV_FS_8000
|
||||
AUDIO_SAMPLE_RATE_TX = 8000
|
||||
AUDIO_SAMPLE_RATE_TX = 48000
|
||||
assert (AUDIO_SAMPLE_RATE_TX % MODEM_SAMPLE_RATE) == 0
|
||||
|
||||
# check if we want to use an audio device then do an pyaudio init
|
||||
|
@ -73,6 +72,9 @@ if AUDIO_OUTPUT_DEVICE != -1:
|
|||
)
|
||||
|
||||
|
||||
AUDIO_FRAMES_PER_BUFFER_8K = int(AUDIO_FRAMES_PER_BUFFER/codec2.api.FDMDV_OS_48)
|
||||
resampler = codec2.resampler()
|
||||
|
||||
# data binary string
|
||||
data_out = b'HELLO WORLD!'
|
||||
|
||||
|
@ -134,21 +136,22 @@ for i in range(1,N_BURSTS+1):
|
|||
txbuffer += bytes(mod_out_postamble)
|
||||
|
||||
# append a delay between bursts as audio silence
|
||||
samples_delay = int(MODEM_SAMPLE_RATE*DELAY_BETWEEN_BURSTS*2)
|
||||
mod_out_silence = create_string_buffer(samples_delay)
|
||||
samples_delay = int(MODEM_SAMPLE_RATE*DELAY_BETWEEN_BURSTS)
|
||||
mod_out_silence = create_string_buffer(samples_delay*2)
|
||||
txbuffer += bytes(mod_out_silence)
|
||||
print(f"samples_delay: {samples_delay} DELAY_BETWEEN_BURSTS: {DELAY_BETWEEN_BURSTS}", file=sys.stderr)
|
||||
|
||||
# resample up to 48k
|
||||
x = np.frombuffer(txbuffer, dtype=np.int16)
|
||||
txbuffer_48k = resampler.resample8_to_48(x)
|
||||
print(len(txbuffer), len(x), len(txbuffer_48k), file=sys.stderr)
|
||||
|
||||
# check if we want to use an audio device or stdout
|
||||
if AUDIO_OUTPUT_DEVICE != -1:
|
||||
|
||||
# sample rate conversion from 8000Hz to 48000Hz
|
||||
#audio = audioop.ratecv(txbuffer,2,1,MODEM_SAMPLE_RATE, AUDIO_SAMPLE_RATE_TX, None)
|
||||
stream_tx.write(txbuffer)
|
||||
|
||||
stream_tx.write(txbuffer_48k)
|
||||
else:
|
||||
# print data to terminal for piping the output to other programs
|
||||
sys.stdout.buffer.write(txbuffer)
|
||||
sys.stdout.buffer.write(txbuffer_48k)
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue