MCPcopy Create free account
hub / github.com/Bloom-Engine/engine / bloom_init_audio

Function bloom_init_audio

native/ios/src/lib.rs:1724–1773  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1722
1723#[no_mangle]
1724pub extern "C" fn bloom_init_audio() {
1725 unsafe {
1726 let desc = AudioComponentDescription {
1727 component_type: K_AUDIO_UNIT_TYPE_OUTPUT,
1728 component_sub_type: K_AUDIO_UNIT_SUB_TYPE_REMOTE_IO,
1729 component_manufacturer: K_AUDIO_UNIT_MANUFACTURER_APPLE,
1730 component_flags: 0,
1731 component_flags_mask: 0,
1732 };
1733
1734 let component = AudioComponentFindNext(std::ptr::null_mut(), &desc);
1735 if component.is_null() { return; }
1736
1737 let mut unit: AudioUnit = std::ptr::null_mut();
1738 if AudioComponentInstanceNew(component, &mut unit) != 0 { return; }
1739
1740 let stream_desc = AudioStreamBasicDescription {
1741 sample_rate: 44100.0,
1742 format_id: K_AUDIO_FORMAT_LINEAR_PCM,
1743 format_flags: K_AUDIO_FORMAT_FLAG_IS_FLOAT | K_AUDIO_FORMAT_FLAG_IS_PACKED,
1744 bytes_per_packet: 8,
1745 frames_per_packet: 1,
1746 bytes_per_frame: 8,
1747 channels_per_frame: 2,
1748 bits_per_channel: 32,
1749 reserved: 0,
1750 };
1751
1752 AudioUnitSetProperty(
1753 unit, K_AUDIO_UNIT_PROPERTY_STREAM_FORMAT, K_AUDIO_UNIT_SCOPE_INPUT, 0,
1754 &stream_desc as *const _ as *const c_void,
1755 std::mem::size_of::<AudioStreamBasicDescription>() as u32,
1756 );
1757
1758 let callback_struct = AURenderCallbackStruct {
1759 input_proc: audio_render_callback,
1760 input_proc_ref_con: std::ptr::null_mut(),
1761 };
1762
1763 AudioUnitSetProperty(
1764 unit, K_AUDIO_UNIT_PROPERTY_SET_RENDER_CALLBACK, K_AUDIO_UNIT_SCOPE_INPUT, 0,
1765 &callback_struct as *const _ as *const c_void,
1766 std::mem::size_of::<AURenderCallbackStruct>() as u32,
1767 );
1768
1769 AudioUnitInitialize(unit);
1770 AudioOutputUnitStart(unit);
1771 AUDIO_UNIT = Some(AudioUnitInstance { unit });
1772 }
1773}
1774
1775#[no_mangle]
1776pub extern "C" fn bloom_close_audio() {

Callers 2

initAudioFunction · 0.50
initAudioDeviceFunction · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected