rename
This commit is contained in:
@@ -84,7 +84,7 @@ async def create_device(config: auracast_config.AuracastGlobalConfig) -> AsyncGe
|
|||||||
name=config.device_name,
|
name=config.device_name,
|
||||||
address=config.auracast_device_address,
|
address=config.auracast_device_address,
|
||||||
keystore='JsonKeyStore',
|
keystore='JsonKeyStore',
|
||||||
le_simultaneous_enabled=True
|
#le_simultaneous_enabled=True
|
||||||
)
|
)
|
||||||
|
|
||||||
device = bumble.device.Device.from_config_with_hci(
|
device = bumble.device.Device.from_config_with_hci(
|
||||||
@@ -122,6 +122,24 @@ async def run_broadcast(
|
|||||||
logger.error(color('Periodic advertising not supported', 'red'))
|
logger.error(color('Periodic advertising not supported', 'red'))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
with wave.open(big_config[0].broacast_wav_file_path, 'rb') as wav:
|
||||||
|
logger.info('Encoding wav file into lc3...')
|
||||||
|
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,
|
||||||
|
num_channels=1,
|
||||||
|
input_sample_rate_hz=wav.getframerate(),
|
||||||
|
)
|
||||||
|
frames = list[bytes]()
|
||||||
|
while pcm := wav.readframes(encoder.get_frame_samples()):
|
||||||
|
frames.append(
|
||||||
|
encoder.encode(pcm, num_bytes=global_config.octets_per_frame, bit_depth=wav.getsampwidth() * 8)
|
||||||
|
)
|
||||||
|
del encoder
|
||||||
|
print('Encoding complete.')
|
||||||
|
|
||||||
# Config advertising set
|
# 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_khz}")
|
||||||
basic_audio_announcement0 = bap.BasicAudioAnnouncement(
|
basic_audio_announcement0 = bap.BasicAudioAnnouncement(
|
||||||
@@ -205,7 +223,6 @@ async def run_broadcast(
|
|||||||
primary_advertising_interval_min=100,
|
primary_advertising_interval_min=100,
|
||||||
primary_advertising_interval_max=200,
|
primary_advertising_interval_max=200,
|
||||||
advertising_sid=0,
|
advertising_sid=0,
|
||||||
|
|
||||||
#primary_advertising_phy=hci.HCI_LE_2M_PHY,
|
#primary_advertising_phy=hci.HCI_LE_2M_PHY,
|
||||||
#secondary_advertising_phy=hci.HCI_LE_2M_PHY,
|
#secondary_advertising_phy=hci.HCI_LE_2M_PHY,
|
||||||
# TODO: use 2mbit phy
|
# TODO: use 2mbit phy
|
||||||
@@ -304,6 +321,18 @@ async def run_broadcast(
|
|||||||
direction=bis_link.Direction.HOST_TO_CONTROLLER
|
direction=bis_link.Direction.HOST_TO_CONTROLLER
|
||||||
)
|
)
|
||||||
|
|
||||||
|
frames_iterator = itertools.cycle(frames)
|
||||||
|
logging.info("Broadcasting...")
|
||||||
|
|
||||||
|
def on_packet_complete(event):
|
||||||
|
frame = next(frames_iterator)
|
||||||
|
big0.bis_links[0].write(frame)
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
@@ -338,7 +367,10 @@ if __name__ == "__main__":
|
|||||||
bigs = [
|
bigs = [
|
||||||
auracast_config.broadcast_de
|
auracast_config.broadcast_de
|
||||||
]
|
]
|
||||||
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(
|
broadcast(
|
||||||
global_conf,
|
global_conf,
|
||||||
Reference in New Issue
Block a user