; ; @ANO_SCRIPT_NAME audio_play ; @ANO_SCRIPT_VERSION 0.0.1 ; @ANO_SCRIPT_DESCRIPTION Simple audio noise player example ; ; @ANO_FLAGS_USE_PROTOS [ ] ; @ANO_FLAGS_VAR_NAME_SUBS [ ] ; @ANO_FLAGS_VAR_WARN_UNUSED [ ] ; ; Copyright (c) 2016-2026, Jani Salonen ; All rights reserved. ; ; Small demonstration how to create audible noise and play that along with ; some audio callback functions. ; main [exit: 0] { ; Initialize audio system, this example does nothing if ; --disable-audio was passed to configure script. ; audio_enabled { mov buf_printed (0) mov buf_played (0) audio_init (\ cb_track_play: "cb_play", \ cb_track_mode: NULL, \ cb_track_finish: "cb_finish", \ cb_track_restart: NULL, \ cb_track_cancel: NULL, \ cb_track_pan: NULL, \ cb_track_vol: NULL, \ cb_master_vol: NULL, \ cb_buffer_start: "cb_buf_start", \ cb_buffer_done: "cb_buf_done") ; Create one second white noise... ; _ahnd = audio_create_noise (\ seconds: 1.0, pink: 0.0, brown: 0.0) ; ...start playing it... ; audio_play (\ audio_handle: _ahnd, volume: 0.1, pan: 0.0) ; ...wait until it finishes... ; audio_wait (\ audio_handle: _ahnd) ; ...and close audio track. ; audio_close (\ audio_handle: _ahnd) } } _AUDIOCB_PLAY_ callback cb_play (_hnd, _vol, _pan, _data_size, \ _ch1_data, _ch1_vol, _ch2_data, _ch2_vol) { ; This callback is called when track starts playing. ; print "Track " . _hnd . " playing " . _data_size . " samples using" \ " volume of " . _vol . " and panning of " . _pan . ".\n\n" } _AUDIOCB_FINISH_ callback cb_finish (_hnd, _data_size, \ _ch1_data, _ch2_data) { ; This callback is called when track finishes playing. ; print "Track " . _hnd . " finished playing " . _data_size . \ " samples, " . buf_played . " buffers in total.\n\n" } _AUDIOCB_START_ callback cb_buf_start (_buf_data, _buf_channels, _buf_speed, \ _buf_size, _buf_samplesize, _buf_be, _buf_signed) { ; This callback is called when internal data buffer is about to be ; processed. ; ; Print buffer info only once. ; mov rc (buf_printed) end_unless_zero print "Buffer start, data address: " . _buf_data . "\n" print "Buffer size: " . _buf_size . " bytes\n" print "Channels: " . _buf_channels . "\n" print "Sample rate: " . _buf_speed . " Hz\n" print "Sample size: " . _buf_samplesize . " bytes\n" print "Big endian: " . _buf_be . "\n" print "Signed: " . _buf_signed . "\n\n" } _AUDIOCB_DONE_ callback cb_buf_done (_buf_data, _buf_channels, _buf_speed, \ _buf_size, _buf_samplesize, _buf_be, _buf_signed, _usecs) { ; This callback is called when internal data buffer was processed. ; inc buf_played ; Print buffer info only once. ; mov rc (buf_printed) end_unless_zero mov buf_printed (1) print "One buffer done, processing time in μsecs: " . _usecs . "\n\n" }