#!/usr/bin/liquidsoap
# Example liquidsoap streaming from op25 to icecast
# (c) 2019-2021 gnorbury@bondcar.com, wllmbecks@gmail.com
#
set("log.stdout", true)
set("log.file.path", "/home/pi/op25/op25/gr-op25_repeater/apps/liquidsoap.log")
set("log.file", true)
set("log.level", 2)
# Make the native sample rate compatible with op25
set("frame.audio.samplerate", 8000)
input_A = mksafe(input.external(buffer=0.25, channels=2, samplerate=8000, restart_on_error=false, "./audio.py -u 23450 -x 1.25 -s"))
input_B = mksafe(input.external(buffer=0.25, channels=2, samplerate=8000, restart_on_error=false, "./audio.py -u 23460 -x 1.25 -s"))
# Consider increasing the buffer value on slow systems such as RPi3. e.g. buffer=0.25
# Longer buffer results in less choppy audio but at the expense of increased latency.
# OPTIONAL AUDIO SIGNAL PROCESSING BLOCKS
# Uncomment to enable
#
# High pass filter
#input_A = filter.iir.butterworth.high(frequency = 200.0, order = 4, input_A)
#input_B = filter.iir.butterworth.high(frequency = 200.0, order = 4, input_B)
# Low pass filter
#input_A = filter.iir.butterworth.low(frequency = 3250.0, order = 4, input_A)
#input_B = filter.iir.butterworth.low(frequency = 3250.0, order = 4, input_B)
# Compand
input_A = compand(input_A, mu = 0.5)
input_B = compand(input_B, mu = 0.5)
# Process "Input_A" & "Input_B" into "Left" & "Right" channel components
left = audio_to_stereo(input_A)
left = stereo.pan(pan=1., input_A)
right = audio_to_stereo(input_B)
right = stereo.pan(pan=-1., input_B)
# Combine "Left" & "Right" channel components into stereo output to local speaker
speaker = mksafe(add(normalize=false, [left,right]))
# LOCAL AUDIO OUTPUT
# Uncomment the appropriate line below to enable local sound
#
# Default audio subsystem
#out (speaker)
#
# PulseAudio
#output.pulseaudio(speaker)
#
# ALSA
output.alsa(speaker)
# ICECAST STREAMING
# Uncomment to enable output to an icecast server
# Change the "host", "password", and "mount" strings appropriately first!
# For metadata to work properly, the host address given here MUST MATCH the address in op25's meta.json file
#
# Stream to broadcastify.com
output.icecast(%mp3(bitrate=16, samplerate=22050, stereo=false), description="op25", genre="Public Safety", url="", fallible=false,
icy_metadata="true", host="audiox.broadcastify.com", port=80, mount="BCFY_Mount, password="BCFY_Password",mean(input_A))
# Stream to local icecast server
output.icecast(%mp3(bitrate=16, samplerate=22050, stereo=false), description="op25", genre="Public Safety", url="", fallible=false,
icy_metadata="true", host="localhost", port=8000, mount="op25", password="hackme",mean(input_B))