make dualcast work
This commit is contained in:
@@ -112,10 +112,13 @@ def run_async(async_command: Coroutine) -> None:
|
||||
color('!!! An error occurred while executing the command:', 'red'), message
|
||||
)
|
||||
|
||||
handle0 = None
|
||||
handle1 = None
|
||||
|
||||
async def run_broadcast(
|
||||
global_config : auracast_config.AuracastGlobalConfig,
|
||||
big_config: List[auracast_config.AuracastBigConfig]
|
||||
|
||||
|
||||
) -> None:
|
||||
async with create_device(global_config) as device:
|
||||
if not device.supports_le_periodic_advertising:
|
||||
@@ -128,7 +131,7 @@ async def run_broadcast(
|
||||
logger.info('Frame rate of .wav file is: %s', wav.getframerate())
|
||||
encoder = lc3.Encoder(
|
||||
frame_duration_us=global_config.frame_duration_us,
|
||||
sample_rate_hz=global_config.auracast_sampling_rate_khz,
|
||||
sample_rate_hz=global_config.auracast_sampling_rate_hz,
|
||||
num_channels=1,
|
||||
input_sample_rate_hz=wav.getframerate(),
|
||||
)
|
||||
@@ -141,7 +144,7 @@ async def run_broadcast(
|
||||
print('Encoding complete.')
|
||||
|
||||
# Config advertising set
|
||||
bap_sampling_freq = getattr(bap.SamplingFrequency, f"FREQ_{global_config.auracast_sampling_rate_khz}")
|
||||
bap_sampling_freq = getattr(bap.SamplingFrequency, f"FREQ_{global_config.auracast_sampling_rate_hz}")
|
||||
basic_audio_announcement0 = bap.BasicAudioAnnouncement(
|
||||
presentation_delay=global_config.presentation_delay_us,
|
||||
subgroups=[
|
||||
@@ -150,7 +153,7 @@ async def run_broadcast(
|
||||
codec_specific_configuration=bap.CodecSpecificConfiguration(
|
||||
sampling_frequency=bap_sampling_freq,
|
||||
frame_duration=bap.FrameDuration.DURATION_10000_US,
|
||||
octets_per_codec_frame=global_config.octets_per_frame,
|
||||
octets_per_codec_frame=global_config.octets_per_frame,
|
||||
),
|
||||
metadata=le_audio.Metadata(
|
||||
[
|
||||
@@ -184,7 +187,7 @@ async def run_broadcast(
|
||||
codec_specific_configuration=bap.CodecSpecificConfiguration(
|
||||
sampling_frequency=bap_sampling_freq,
|
||||
frame_duration=bap.FrameDuration.DURATION_10000_US,
|
||||
octets_per_codec_frame=global_config.octets_per_frame,
|
||||
octets_per_codec_frame=global_config.octets_per_frame,
|
||||
),
|
||||
metadata=le_audio.Metadata(
|
||||
[
|
||||
@@ -321,18 +324,36 @@ async def run_broadcast(
|
||||
direction=bis_link.Direction.HOST_TO_CONTROLLER
|
||||
)
|
||||
|
||||
frames_iterator = itertools.cycle(frames)
|
||||
frames_iterator0 = itertools.cycle(frames)
|
||||
frames_iterator1 = itertools.cycle(frames)
|
||||
frame0 = next(frames_iterator0)
|
||||
frame1 = next(frames_iterator1)
|
||||
|
||||
# Get the corresponding handles first
|
||||
logging.info("Determine broadcast handles")
|
||||
|
||||
# Define on packet complete function to get the handle for each broadcast
|
||||
handle0 = big0.bis_links[0].handle
|
||||
handle1 = big1.bis_links[0].handle
|
||||
|
||||
logging.info("Broadcasting...")
|
||||
|
||||
def on_packet_complete(event):
|
||||
frame = next(frames_iterator)
|
||||
big0.bis_links[0].write(frame)
|
||||
|
||||
event_handle = event.connection_handles[0]
|
||||
if event_handle == handle0:
|
||||
frame0 = next(frames_iterator0)
|
||||
big0.bis_links[0].write(frame0)
|
||||
elif event_handle == handle1:
|
||||
frame1 = next(frames_iterator1)
|
||||
big1.bis_links[0].write(frame1)
|
||||
else:
|
||||
raise NotImplementedError('Unkown connection handle')
|
||||
|
||||
device.host.on('hci_number_of_completed_packets_event', on_packet_complete)
|
||||
|
||||
on_packet_complete('') # Send the first packet, to get the event loop running
|
||||
|
||||
|
||||
# Send the first packets, to get the event loop running
|
||||
big0.bis_links[0].write(frame0)
|
||||
big1.bis_links[0].write(frame1)
|
||||
|
||||
while True:
|
||||
await asyncio.sleep(1)
|
||||
@@ -367,10 +388,10 @@ if __name__ == "__main__":
|
||||
bigs = [
|
||||
auracast_config.broadcast_de
|
||||
]
|
||||
global_conf.auracast_sampling_rate_khz=16000
|
||||
global_conf.octets_per_frame=40 # 16kbps@8kHz
|
||||
|
||||
#global_conf.octets_per_frame=60# 48kbps@24kHz
|
||||
#global_conf.auracast_sampling_rate_khz=16000
|
||||
#global_conf.octets_per_frame=40 # 16kbps@8kHz
|
||||
|
||||
global_conf.octets_per_frame=60# 48kbps@24kHz
|
||||
|
||||
broadcast(
|
||||
global_conf,
|
||||
|
||||
Reference in New Issue
Block a user