.\" .\" UnixCW CW Tutor Package - LIBCW .\" Copyright (C) 2001-2006 Simon Baldwin (simon_baldwin@yahoo.com) .\" Copyright (C) 2011-2021 Kamil Ignacak (acerion@wp.pl) .\" .\" This program is free software; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License .\" as published by the Free Software Foundation; either version 2 .\" of the License, or (at your option) any later version. .\" .\" This program is distributed in the hope that it will be useful, .\" but WITHOUT ANY WARRANTY; without even the implied warranty of .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the .\" GNU General Public License for more details. .\" .\" You should have received a copy of the GNU General Public License along .\" with this program; if not, write to the Free Software Foundation, Inc., .\" 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. .\" .\" .TH LIBCW 3 "CW Tutor Package" "libcw ver. 7.0.0" \" -*- nroff -*- .SH NAME .\" libcw \- general purpose Morse code functions library .\" .\" .\" .SH SYNOPSIS .\" .nf .B #include .sp .fi .BI "int cw_generator_new(int audio_system, const char *device)" .br .BI "void cw_generator_delete(void)" .br .BI "int cw_generator_start(void)" .br .BI "void cw_generator_stop(void)" .br .BI "int cw_set_send_speed(int new_value)" .br .BI "int cw_set_frequency(int new_value)" .br .BI "int cw_set_volume(int new_value)" .br .BI "int cw_set_gap(int new_value)" .br .BI "int cw_set_weighting(int new_value)" .br .BI "int cw_get_send_speed(void)" .br .BI "int cw_get_frequency(void)" .br .BI "int cw_get_volume(void)" .br .BI "int cw_get_gap(void)" .br .BI "int cw_get_weighting(void)" .br .BI "void cw_get_send_parameters(int *dot_usecs, int *dash_usecs," .br .BI " int *end_of_element_usecs," .br .BI " int *end_of_character_usecs, int *end_of_word_usecs," .br .BI " int *additional_usecs, int *adjustment_usecs)" .br .BI "int cw_send_dot(void)" .br .BI "int cw_send_dash(void)" .br .BI "int cw_send_character_space(void)" .br .BI "int cw_send_word_space(void)" .br .BI "int cw_send_representation(const char *representation)" .br .BI "int cw_send_representation_partial(const char *representation)" .br .BI "int cw_send_character(char c)" .br .BI "int cw_send_character_partial(char c)" .br .BI "int cw_send_string(const char *string)" .br .BI "void cw_reset_send_receive_parameters(void)" .br .BI "const char *cw_get_console_device(void)" .br .BI "const char *cw_get_soundcard_device(void)" .br .BI "const char *cw_generator_get_audio_system_label(void)" .br .BI "int cw_generator_remove_last_character(void)" .br .BI "int cw_register_tone_queue_low_callback(void (*callback_func)(void*), void *callback_arg, int level)" .br .BI "bool cw_is_tone_busy(void)" .br .BI "int cw_wait_for_tone(void)" .br .BI "int cw_wait_for_tone_queue(void)" .br .BI "int cw_wait_for_tone_queue_critical(int level)" .br .BI "bool cw_is_tone_queue_full(void)" .br .BI "int cw_get_tone_queue_capacity(void)" .br .BI "int cw_get_tone_queue_length(void)" .br .BI "void cw_flush_tone_queue(void)" .br .BI "void cw_reset_tone_queue(void)" .br .BI "int cw_queue_tone(int usecs, int frequency)" .br .BI "int cw_set_receive_speed(int new_value)" .br .BI "int cw_get_receive_speed(void)" .br .BI "int cw_set_tolerance(int new_value)" .br .BI "int cw_get_tolerance(void)" .br .BI "void cw_get_receive_parameters(int *dot_usecs, int *dash_usecs," .br .BI " int *dot_min_usecs, int *dot_max_usecs," .br .BI " int *dash_min_usecs, int *dash_max_usecs," .br .BI " int *end_of_element_min_usecs," .br .BI " int *end_of_element_max_usecs," .br .BI " int *end_of_element_ideal_usecs," .br .BI " int *end_of_character_min_usecs," .br .BI " int *end_of_character_max_usecs," .br .BI " int *end_of_character_ideal_usecs," .br .BI " int *adaptive_threshold)" .br .BI "int cw_set_noise_spike_threshold(int new_value)" .br .BI "int cw_get_noise_spike_threshold(void)" .br .BI "void cw_get_receive_statistics(double *dot_sd, double *dash_sd," .br .BI " double *element_end_sd, double *character_end_sd)" .br .BI "void cw_reset_receive_statistics(void)" .br .BI "void cw_enable_adaptive_receive(void)" .br .BI "void cw_disable_adaptive_receive(void)" .br .BI "bool cw_get_adaptive_receive_state(void)" .br .BI "int cw_start_receive_tone(const struct timeval *timestamp)" .br .BI "int cw_end_receive_tone(const struct timeval *timestamp)" .br .BI "int cw_receive_buffer_dot(const struct timeval *timestamp)" .br .BI "int cw_receive_buffer_dash(const struct timeval *timestamp)" .br .BI "int cw_receive_representation(const struct timeval *timestamp," .br .BI " /* out */ char *representation," .br .BI " /* out */ bool *is_end_of_word," .br .BI " /* out */ bool *is_error)" .br .BI "int cw_receive_character(const struct timeval *timestamp," .br .BI " /* out */ char *c," .br .BI " /* out */ bool *is_end_of_word," .br .BI " /* out */ bool *is_error)" .br .BI "void cw_clear_receive_buffer(void)" .br .BI "int cw_get_receive_buffer_capacity(void)" .br .BI "int cw_get_receive_buffer_length(void)" .br .BI "void cw_reset_receive(void)" .br .BI "void cw_register_keying_callback(void (*callback_func)(void*, int), void *callback_arg)" .br .BI "void cw_enable_iambic_curtis_mode_b(void)" .br .BI "void cw_disable_iambic_curtis_mode_b(void)" .br .BI "int cw_get_iambic_curtis_mode_b_state(void)" .br .BI "int cw_notify_keyer_paddle_event(int dot_paddle_state, int dash_paddle_state)" .br .BI "int cw_notify_keyer_dot_paddle_event(int dot_paddle_state)" .br .BI "int cw_notify_keyer_dash_paddle_event(int dash_paddle_state)" .br .BI "void cw_get_keyer_paddles(int *dot_paddle_state, int *dash_paddle_state)" .br .BI "void cw_get_keyer_paddle_latches(int *dot_paddle_latch_state, int *dash_paddle_latch_state)" .br .BI "bool cw_is_keyer_busy(void)" .br .BI "int cw_wait_for_keyer_element(void)" .br .BI "int cw_wait_for_keyer(void)" .br .BI "void cw_reset_keyer(void)" .br .BI "int cw_notify_straight_key_event(int key_state)" .br .BI "int cw_get_straight_key_state(void)" .br .BI "bool cw_is_straight_key_busy(void)" .br .BI "void cw_reset_straight_key(void)" .br .BI "bool cw_is_alsa_possible(const char * device_name)" .br .BI "bool cw_is_console_possible(const char * device_name)" .br .BI "int cw_get_character_count(void)" .br .BI "void cw_list_characters(char * list)" .br .BI "int cw_get_maximum_representation_length(void)" .br .BI "int cw_lookup_character(char character, char * representation)" .br .BI "char * cw_character_to_representation(int character)" .br .BI "int cw_check_representation(const char * representation)" .br .BI "bool cw_representation_is_valid(const char * representation)" .br .BI "int cw_lookup_representation(const char * representation, char * character)" .br .BI "int cw_representation_to_character(const char * representation)" .br .BI "int cw_get_procedural_character_count(void)" .br .BI "void cw_list_procedural_characters(char * list)" .br .BI "int cw_get_maximum_procedural_expansion_length(void)" .br .BI "int cw_lookup_procedural_character(char character, char *expansion, int * is_usually_expanded)" .br .BI "int cw_get_maximum_phonetic_length(void)" .br .BI "int cw_lookup_phonetic(char character, char * phonetic)" .br .BI "bool cw_character_is_valid(char character)" .br .BI "int cw_check_character(char character)" .br .BI "bool cw_string_is_valid(const char * string)" .br .BI "int cw_check_string(const char * string)" .br .BI "void cw_set_debug_flags(uint32_t flags)" .br .BI "void cw_debug_set_flags(cw_debug_t * debug_object, uint32_t flags)" .br .BI "uint32_t cw_get_debug_flags(void)" .br .BI "uint32_t cw_debug_get_flags(const cw_debug_t * debug_object)" .br .BI "bool cw_debug_has_flag(const cw_debug_t * debug_object, uint32_t flag)" .br .BI "int cw_generator_set_tone_slope(cw_gen_t * gen, int slope_shape, int slope_duration)" .br .BI "bool cw_is_null_possible(__attribute__((unused)) const char * device_name)" .br .BI "bool cw_is_oss_possible(const char * device_name)" .br .BI "bool cw_is_pa_possible(const char * device_name)" .br .BI "void cw_block_callback(int block)" .br .BI "int cw_register_signal_handler(int signal_number, void (*callback_func)(int))" .br .BI "int cw_unregister_signal_handler(int signal_number)" .br .BI "int cw_version(void)" .br .BI "void cw_license(void)" .br .BI "const char * cw_get_audio_system_label(int sound_system)" .br .BI "void cw_get_speed_limits(int * min_speed, int * max_speed)" .br .BI "void cw_get_frequency_limits(int * min_frequency, int * max_frequency)" .br .BI "void cw_get_volume_limits(int * min_volume, int * max_volume)" .br .BI "void cw_get_gap_limits(int * min_gap, int * max_gap)" .br .BI "void cw_get_tolerance_limits(int * min_tolerance, int * max_tolerance)" .br .BI "void cw_get_weighting_limits(int * min_weighting, int * max_weighting)" .br .BI "void cw_complete_reset(void)" .br .fi .PP .\" .\" .\" .SS DESCRIPTION .\" .B libcw is a general purpose CW (Morse code) functions library. It contains routines for converting characters into Morse code representations and back again, for sending Morse code characters, and for receiving characters. It also contains routines to emulate an Iambic Morse keyer, and a straight key. .PP The library can be included in any program that wishes to make use of these features. It forms the heart of three Morse code tutor applications that accompany the package in which it is distributed. .PP See the \fBcw\fP(7) man page for information on Morse code timings, and the dot and dash representations for the various Morse characters. .\" .\" .\" .SS TONE QUEUE .\" .B libcw contains an inbuilt tone queue. The queue is emptied by background processing, using SIGALRM calls and itimers, so a caller program can continue with other tasks while the library sends tones and keys any external device. .PP As well as being used by the library functions that sound Morse code characters and provide a keyer sidetone, the primitive tone queue functions are publicly available to caller programs. .PP .\" .\" .\" .SS CONTROLLING AN EXTERNAL DEVICE .\" .B libcw may be passed the address of a function that controls external keying. This function is called each time the library changes the keying state, either as a result of sending a Morse character or representation, or as a result of an iambic keyer or straight key state change. The argument passed is a single integer, TRUE for key-down, and FALSE for key-up. .PP .B libcw calls the external keying function only when the keying state changes. A call is likely each time a tone is taken off the tone queue. .PP .\" .\" .\" .SS SENDING CW CHARACTERS AND STRINGS .\" .B libcw offers several functions that send individual characters and character strings as Morse code. It also offers functions that allow specialized 'representations' to be sent. A 'representation' is an ASCII string that consists of only the characters '.' and '-'. .PP Characters and strings are converted into representations, and then the correct tones for the dots and dashes in these representations are queued on the tone queue, for action by the background queue emptying process. .PP .\" .\" .\" .SS RECEIVING CW CHARACTERS AND REPRESENTATIONS .\" .B libcw contains functions to allow it to receive Morse code. To receive, the library must be told when a tone start is detected, and when a tone end is detected. It then determines whether the tone was a dot or a dash depending on the timing difference between the two. After the required silence gap has passed, the library may be queried to see what the received representation or character was. .PP Errors in receiving may be detected by means of the flags passed back on receive character functions. .PP .\" .\" .\" .SS IAMBIC KEYER .\" .B libcw offers functions to simulate an Iambic Morse keyer. The caller program needs to tell the library of paddle state changes. Iambic keyer functions are mutually exclusive with character send and straight key functions. .PP .\" .\" .\" .SS STRAIGHT KEY .\" .B libcw offers simple functions to allow effective pass-through of straight key information. The caller program needs to tell the library of key state changes. Straight key functions are mutually exclusive with character send and iambic keyer functions. .PP .\" .\" .\" .SS RETURN CODES .\" Some of the library's function return a return code of type int. The return code has two values, as defined in libcw.h: \fBCW_SUCCESS\fP or \fBCW_FAILURE\fP. The two symbolic constants are guaranteed to be identical to boolean \fBtrue\fP and \fBfalse\fP. .PP .\" .\" .\" .SS FUNCTIONS The following list describes the functions available to a \fBlibcw\fP caller: .sp .br .B "int cw_generator_new(int audio_system, const char *device)" .br Brief: Create new generator Allocate memory for new generator data structure, set up default values of some of the generator's properties. The function does not start the generator (generator does not produce a sound), you have to use cw_generator_start() for this. Notice that the function doesn't return a generator variable. There is at most one generator variable at any given time. You can't have two generators. In some future version of the library the function will return pointer to newly allocated generator, and then you could have as many of them as you want, but not yet. \fBaudio_system\fP can be one of following: NULL, console, OSS, ALSA, PulseAudio, soundcard. See "enum cw_audio_systems" in libcw.h for exact names of symbolic constants. .br Parameter: audio_system - audio system to be used by the generator .br Parameter: device - name of audio device to be used; if NULL then library will use default device. .sp .br .B "void cw_generator_delete(void)" .br Brief: Deallocate generator Deallocate/destroy generator data structure created with call to cw_generator_new(). You can't start nor use the generator after the call to this function. .sp .br .B "int cw_generator_start(void)" .br Brief: Start a generator Start producing tones using generator created with cw_generator_new(). The source of tones is a tone queue associated with the generator. If the tone queue is empty, the generator will wait for new tones to be queued. .br Returns: CW_FAILURE on errors .br Returns: CW_SUCCESS on success .sp .br .B "void cw_generator_stop(void)" .br Brief: Shut down a generator Silence tone generated by generator (level of generated sine wave is set to zero, with falling slope), and shut the generator down. The shutdown does not erase generator's configuration. If you want to have this generator running again, you have to call cw_generator_start(). .sp .br .B "int cw_set_send_speed(int new_value)" .br Brief: Set sending speed of generator See libcw.h/CW_SPEED_{INITIAL|MIN|MAX} for initial/minimal/maximal value of send speed. errno is set to EINVAL if \fBnew_value\fP is out of range. .br Parameter: new_value - new value of send speed to be assigned to generator .br Returns: CW_SUCCESS on success .br Returns: CW_FAILURE on failure .sp .br .B "int cw_set_frequency(int new_value)" .br Brief: Set frequency of generator Set frequency of sound wave generated by generator. The frequency must be within limits marked by CW_FREQUENCY_MIN and CW_FREQUENCY_MAX. See libcw.h/CW_FREQUENCY_{INITIAL|MIN|MAX} for initial/minimal/maximal value of frequency. errno is set to EINVAL if \fBnew_value\fP is out of range. .br Parameter: new_value - new value of frequency to be assigned to generator .br Returns: CW_SUCCESS on success .br Returns: CW_FAILURE on failure .sp .br .B "int cw_set_volume(int new_value)" .br Brief: Set volume of generator Set volume of sound wave generated by generator. The volume must be within limits marked by CW_VOLUME_MIN and CW_VOLUME_MAX. Note that volume settings are not fully possible for the console speaker. In this case, volume settings greater than zero indicate console speaker sound is on, and setting volume to zero will turn off console speaker sound. See libcw.h/CW_VOLUME_{INITIAL|MIN|MAX} for initial/minimal/maximal value of volume. errno is set to EINVAL if \fBnew_value\fP is out of range. .br Parameter: new_value - new value of volume to be assigned to generator .br Returns: CW_SUCCESS on success .br Returns: CW_FAILURE on failure .sp .br .B "int cw_set_gap(int new_value)" .br Brief: Set sending gap of generator See libcw.h/CW_GAP_{INITIAL|MIN|MAX} for initial/minimal/maximal value of gap. errno is set to EINVAL if \fBnew_value\fP is out of range. Notice that this function also sets the same gap value for library's receiver. .br Parameter: new_value - new value of gap to be assigned to generator .br Returns: CW_SUCCESS on success .br Returns: CW_FAILURE on failure .sp .br .B "int cw_set_weighting(int new_value)" .br Brief: Set sending weighting for generator See libcw.h/CW_WEIGHTING_{INITIAL|MIN|MAX} for initial/minimal/maximal value of weighting. errno is set to EINVAL if \fBnew_value\fP is out of range. .br Parameter: new_value - new value of weighting to be assigned for generator .br Returns: CW_SUCCESS on success .br Returns: CW_FAILURE on failure .sp .br .B "int cw_get_send_speed(void)" .br Brief: Get sending speed from generator .br Returns: current value of the generator's send speed .sp .br .B "int cw_get_frequency(void)" .br Brief: Get frequency from generator Function returns "frequency" parameter of generator, even if the generator is stopped, or volume of generated sound is zero. .br Returns: current value of generator's frequency .sp .br .B "int cw_get_volume(void)" .br Brief: Get sound volume from generator Function returns "volume" parameter of generator, even if the generator is stopped. .br Returns: current value of generator's sound volume .sp .br .B "int cw_get_gap(void)" .br Brief: Get sending gap from generator .br Returns: current value of generator's sending gap .sp .br .B "int cw_get_weighting(void)" .br Brief: Get sending weighting from generator .br Returns: current value of generator's sending weighting .sp .br .B "void cw_get_send_parameters(int *dot_usecs, int *dash_usecs," .br .B " int *end_of_element_usecs," .br .B " int *end_of_character_usecs, int *end_of_word_usecs," .br .B " int *additional_usecs, int *adjustment_usecs)" .br Brief: Get timing parameters for sending Return the low-level timing parameters calculated from the speed, gap, tolerance, and weighting set. Parameter values are returned in microseconds. Use NULL for the pointer argument to any parameter value not required. .br Parameter: dot_usecs .br Parameter: dash_usecs .br Parameter: end_of_element_usecs .br Parameter: end_of_character_usecs .br Parameter: end_of_word_usecs .br Parameter: additional_usecs .br Parameter: adjustment_usecs .sp .br .B "int cw_send_dot(void)" .br Brief: Low-level primitive for sending a Dot Mark Low-level primitive function able to play/send single Dot Mark. The function appends to a tone queue a normal inter-mark-space after the Dot Mark. .br Returns: CW_SUCCESS on success .br Returns: CW_FAILURE on failure .sp .br .B "int cw_send_dash(void)" .br Brief: Low-level primitive for sending a Dash Mark Low-level primitive function able to play/send single Dash Mark. The function appends to a tone queue a normal inter-mark-space after the Dash Mark. .br Returns: CW_SUCCESS on success .br Returns: CW_FAILURE on failure .sp .br .B "int cw_send_character_space(void)" .br The function enqueues space of specific length: together with previously implicitly enqueued inter-mark-space of size 1 Unit, enqueueing this space will form a full inter-character-space of size 3 Units. .br Returns: CW_SUCCESS on success .br Returns: CW_FAILURE on failure .sp .br .B "int cw_send_word_space(void)" .br The function enqueues space of specific length: together with previously implicitly enqueued inter-mark-space of size 1 Unit and implicitly or explicitly enqueued inter-character-space, enqueueing this space will form a full inter-word-space of size 7 Units. .br Returns: CW_SUCCESS on success .br Returns: CW_FAILURE on failure .sp .br .B "int cw_send_representation(const char *representation)" .br Brief: Check, then send the given string as dots and dashes. The representation passed in is assumed to be a complete Morse character; that is, all post-character delays will be added when the character is sent. On success, the routine returns CW_SUCCESS. On failure, it returns CW_FAILURE, with errno set to EINVAL if any character of the representation is invalid, EBUSY if the sound card, console speaker, or keying system is busy, or EAGAIN if the tone queue is full, or if there is insufficient space to queue the tones or the representation. .br Parameter: representation - representation to send .br Returns: CW_SUCCESS on success .br Returns: CW_FAILURE on failure .sp .br .B "int cw_send_representation_partial(const char *representation)" .br Brief: Check, then send the given string as dots and dashes The \fBrepresentation\fP passed in is assumed to be only part of a larger Morse representation; that is, no post-character delays will be added when the character is sent. On success, the routine returns CW_SUCCESS. On failure, it returns CW_FAILURE, with errno set to EINVAL if any character of the representation is invalid, EBUSY if the sound card, console speaker, or keying system is busy, or EAGAIN if the tone queue is full, or if there is insufficient space to queue the tones for the representation. .sp .br .B "int cw_send_character(char c)" .br Brief: Look up and send a given ASCII character as Morse The end of character delay is appended to the Morse sent. On success the routine returns CW_SUCCESS. On failure the function returns CW_FAILURE and sets errno. errno is set to ENOENT if the given character \fBc\fP is not a valid Morse character. errno is set to EBUSY if current audio sink or keying system is busy. errno is set to EAGAIN if the generator's tone queue is full, or if there is insufficient space to queue the tones for the character. This routine returns as soon as the character has been successfully queued for sending; that is, almost immediately. The actual sending happens in background processing. See cw_wait_for_tone() and cw_wait_for_tone_queue() for ways to check the progress of sending. .br Parameter: c - character to send .br Returns: CW_SUCCESS on success .br Returns: CW_FAILURE on failure .sp .br .B "int cw_send_character_partial(char c)" .br Brief: Look up and send a given ASCII character as Morse code "partial" means that the "end of character" delay is not appended to the Morse code sent by the function, to support the formation of combination characters. On success the function returns CW_SUCCESS. On failure the function returns CW_FAILURE and sets errno. errno is set to ENOENT if the given character \fBc\fP is not a valid Morse character. errno is set to EBUSY if the audio sink or keying system is busy. errno is set to EAGAIN if the tone queue is full, or if there is insufficient space to queue the tones for the character. This routine queues its arguments for background processing. See cw_wait_for_tone() and cw_wait_for_tone_queue() for ways to check the progress of sending. .br Parameter: c - character to send .br Returns: CW_SUCCESS on success .br Returns: CW_FAILURE on failure .sp .br .B "int cw_send_string(const char *string)" .br Brief: Send a given ASCII string in Morse code errno is set to ENOENT if any character in the string is not a valid Morse character. errno is set to EBUSY if audio sink or keying system is busy. errno is set to EAGAIN if the tone queue is full or if the tone queue runs out of space part way through queueing the string. However, an indeterminate number of the characters from the string will have already been queued. For safety, clients can ensure the tone queue is empty before queueing a string, or use cw_send_character() if they need finer control. This routine queues its arguments for background processing, the actual sending happens in background processing. See cw_wait_for_tone() and cw_wait_for_tone_queue() for ways to check the progress of sending. .br Parameter: string - string to send .br Returns: CW_SUCCESS on success .br Returns: CW_FAILURE on failure .sp .br .B "void cw_reset_send_receive_parameters(void)" .br Brief: Reset send/receive parameters Reset the library speed, frequency, volume, gap, tolerance, weighting, adaptive receive, and noise spike threshold to their initial default values: send/receive speed 12 WPM, volume 70 %, frequency 800 Hz, gap 0 dots, tolerance 50 %, and weighting 50 %. .sp .br .B "const char *cw_get_console_device(void)" .br Brief: Return char string with console device path Returned pointer is owned by library. .br Returns: char string with current console device path .sp .br .B "const char *cw_get_soundcard_device(void)" .br Brief: Return char string with soundcard device name/path Returned pointer is owned by library. .br Returns: char string with current soundcard device name or device path .sp .br .B "const char *cw_generator_get_audio_system_label(void)" .br Brief: Get a readable label of current audio system The function returns one of following strings: None, Null, Console, OSS, ALSA, PulseAudio, Soundcard .br Returns: audio system's label .sp .br .B "int cw_generator_remove_last_character(void)" .br Brief: Remove last character from queue of already enqueued characters If the character is not actually played by sound sink yet, library may be able to remove the character. The character's Dots and Dashes won't be played. This function may be useful if user presses backspace in UI to remove/undo a character. If your application doesn't enqueue whole characters or strings of characters but is using low-level cw_send_dot()/cw_send_dash() functions to enqueue individual Marks, don't use this function. This function won't be able to recognize whole characters and is likely to remove more tones than expected. .br Returns: CW_SUCCESS if function managed to remove a last character before it has been played .br Returns: CW_FAILURE otherwise .sp .br .B "int cw_register_tone_queue_low_callback(void (*callback_func)(void*), void *callback_arg, int level)" .br Brief: Register callback for low queue state Register a function to be called automatically by the dequeue routine whenever the count of tones in tone queue falls to a given \fBlevel\fP. To be more precise: the callback is called by queue's dequeue function if, after dequeueing a tone, the function notices that tone queue length has become equal or less than \fBlevel\fP. \fBlevel\fP can't be negative. \fBlevel\fP can't be equal to or larger than tone queue capacity. If \fBlevel\fP is zero, the behaviour of the mechanism is not guaranteed to work correctly. If \fBcallback_func\fP is NULL then the mechanism becomes disabled. \fBcallback_arg\fP will be passed to \fBcallback_arg\fP. errno is set to EINVAL when \fBlevel\fP is invalid. .br Parameter: callback_func - callback function to be registered .br Parameter: callback_arg - argument for callback_func to pass return value .br Parameter: level - low level of queue triggering callback call .br Returns: CW_SUCCESS on successful registration .br Returns: CW_FAILURE on failure .sp .br .B "bool cw_is_tone_busy(void)" .br Brief: Check if tone sender is busy Indicate if the tone sender is busy. .br Returns: true if there are still entries in the tone queue .br Returns: false if the queue is empty .sp .br .B "int cw_wait_for_tone(void)" .br Brief: Wait for the current tone to complete .br Returns: CW_SUCCESS on success .br Returns: CW_FAILURE on failure .sp .br .B "int cw_wait_for_tone_queue(void)" .br Brief: Wait for the tone queue to drain Notice that generator must be running (started with cw_generator_start()) when this function is called, otherwise it will be waiting forever for a change of tone queue's level that will never happen. .br Returns: CW_SUCCESS on success .br Returns: CW_FAILURE on failure .sp .br .B "int cw_wait_for_tone_queue_critical(int level)" .br Brief: Wait for the tone queue to drain until only as many tones as given in level remain queued This routine is for use by programs that want to optimize themselves to avoid the cleanup that happens when the tone queue drains completely; such programs have a short time in which to add more tones to the queue. Notice that generator must be running (started with cw_generator_start()) when this function is called, otherwise it will be waiting forever for a change of tone queue's level that will never happen. If \fBlevel\fP is negative, function sets errno to EINVAL and returns CW_FAILURE. .br Parameter: level - low level in queue, at which to return .br Returns: CW_SUCCESS on success .br Returns: CW_FAILURE on failure .sp .br .B "bool cw_is_tone_queue_full(void)" .br Brief: Indicate if the tone queue is full .br Returns: true if tone queue is full .br Returns: false if tone queue is not full .sp .br .B "int cw_get_tone_queue_capacity(void)" .br Brief: Return the number of entries the tone queue can accommodate .sp .br .B "int cw_get_tone_queue_length(void)" .br Brief: Return the number of entries currently pending in the tone queue .sp .br .B "void cw_flush_tone_queue(void)" .br Brief: Cancel all pending queued tones, and return to silence. If there is a tone in progress, the function will wait until this last one has completed, then silence the tones. .sp .br .B "void cw_reset_tone_queue(void)" .br Cancel all pending queued tones, reset any queue low callback registered, and return to silence. This function is suitable for calling from an application exit handler. .sp .br .B "int cw_queue_tone(int usecs, int frequency)" .br Brief: Primitive access to simple tone generation This routine queues a tone of given duration and frequency. The routine returns CW_SUCCESS on success. If usec or frequency are invalid, it returns CW_FAILURE with errno set to EINVAL. If the sound card, console speaker, or keying function are busy, it returns CW_FAILURE with errno set to EBUSY. If the tone queue is full, it returns false with errno set to EAGAIN. .br Parameter: usecs - duration of queued tone, in microseconds .br Parameter: frequency - frequency of queued tone .br Returns: CW_SUCCESS on success .br Returns: CW_FAILURE on failure .sp .br .B "int cw_set_receive_speed(int new_value)" .br Brief: Set receiving speed of receiver See documentation of cw_set_send_speed() for more information. See libcw.h/CW_SPEED_{INITIAL|MIN|MAX} for initial/minimal/maximal value of receive speed. errno is set to EINVAL if \fBnew_value\fP is out of range. errno is set to EPERM if adaptive receive speed tracking is enabled. .br Parameter: new_value - new value of receive speed to be assigned to receiver .br Returns: CW_SUCCESS on success .br Returns: CW_FAILURE on failure .sp .br .B "int cw_get_receive_speed(void)" .br Brief: Get receiving speed from receiver .br Returns: current value of the receiver's receive speed .sp .br .B "int cw_set_tolerance(int new_value)" .br Brief: Set tolerance for receiver See libcw.h/CW_TOLERANCE_{INITIAL|MIN|MAX} for initial/minimal/maximal value of tolerance. errno is set to EINVAL if \fBnew_value\fP is out of range. .br Parameter: new_value - new value of tolerance to be assigned to receiver .br Returns: CW_SUCCESS on success .br Returns: CW_FAILURE on failure .sp .br .B "int cw_get_tolerance(void)" .br Brief: Get tolerance from receiver .br Returns: current value of receiver's tolerance .sp .br .B "void cw_get_receive_parameters(int *dot_usecs, int *dash_usecs," .br .B " int *dot_min_usecs, int *dot_max_usecs," .br .B " int *dash_min_usecs, int *dash_max_usecs," .br .B " int *end_of_element_min_usecs," .br .B " int *end_of_element_max_usecs," .br .B " int *end_of_element_ideal_usecs," .br .B " int *end_of_character_min_usecs," .br .B " int *end_of_character_max_usecs," .br .B " int *end_of_character_ideal_usecs," .br .B " int *adaptive_threshold)" .br Brief: Get timing parameters for receiving, and adaptive threshold Return the low-level timing parameters calculated from the speed, gap, tolerance, and weighting set. Parameter values are returned in microseconds. Use NULL for the pointer argument to any parameter value not required. .br Parameter: dot_usecs .br Parameter: dash_usecs .br Parameter: dot_min_usecs .br Parameter: dot_max_usecs .br Parameter: dash_min_usecs .br Parameter: dash_max_usecs .br Parameter: end_of_element_min_usecs .br Parameter: end_of_element_max_usecs .br Parameter: end_of_element_ideal_usecs .br Parameter: end_of_character_min_usecs .br Parameter: end_of_character_max_usecs .br Parameter: end_of_character_ideal_usecs .br Parameter: adaptive_threshold .sp .br .B "int cw_set_noise_spike_threshold(int new_value)" .br Brief: Set noise spike threshold for receiver Set the period shorter than which, on receive, received marks are ignored. This allows the "receive mark" functions to apply noise canceling for very short apparent marks. For useful results the value should never exceed the dot length of a dot at maximum speed: 20000 microseconds (the dot length at 60WPM). Setting a noise threshold of zero turns off receive mark noise canceling. The default noise spike threshold is 10000 microseconds. errno is set to EINVAL if \fBnew_value\fP is out of range. .br Parameter: new_value - new value of noise spike threshold to be assigned to receiver .br Returns: CW_SUCCESS on success .br Returns: CW_FAILURE on failure .sp .br .B "int cw_get_noise_spike_threshold(void)" .br Brief: Get noise spike threshold from receiver See documentation of cw_set_noise_spike_threshold() for more information .br Returns: current value of receiver's threshold .sp .br .B "void cw_get_receive_statistics(double *dot_sd, double *dash_sd," .br .B " double *element_end_sd, double *character_end_sd)" .br Brief: Calculate and return receiver's timing statistics These statistics may be used to obtain a measure of the accuracy of received CW. The values \fBdot_sd\fP and \fBdot_sd\fP contain the standard deviation of dot and dash lengths from the ideal values, and \fBelement_end_sd\fP and \fBelement_end_sd\fP the deviations for inter element and inter character spacing. Statistics are held for all timings in a 256 element circular buffer. If any statistic cannot be calculated, because no records for it exist, the returned value is 0.0. Use NULL for the pointer argument to any statistic not required. .br Parameter: dot_sd .br Parameter: dash_sd .br Parameter: element_end_sd .br Parameter: character_end_sd .sp .br .B "void cw_reset_receive_statistics(void)" .br Brief: Clear the receive statistics buffer Clear the receive statistics buffer by removing all records from it and returning it to its initial default state. .sp .br .B "void cw_enable_adaptive_receive(void)" .br Brief: Enable adaptive receive speed tracking If adaptive speed tracking is enabled, the receive functions will attempt to automatically adjust the receive speed setting to match the speed of the incoming Morse code. If it is disabled, the receive functions will use fixed speed settings, and reject incoming Morse which is not at the expected speed. Adaptive speed tracking uses a moving average length of the past N marks as its baseline for tracking speeds. The default state is adaptive speed tracking disabled. .sp .br .B "void cw_disable_adaptive_receive(void)" .br Brief: Disable adaptive receive speed tracking See documentation of cw_enable_adaptive_receive() for more information .sp .br .B "bool cw_get_adaptive_receive_state(void)" .br Brief: Get adaptive receive speed tracking flag The function returns state of "adaptive receive enabled" flag. See documentation of cw_enable_adaptive_receive() for more information .br Returns: true if adaptive speed tracking is enabled .br Returns: false otherwise .sp .br .B "int cw_start_receive_tone(const struct timeval *timestamp)" .br Brief: Signal beginning of receive mark Called on the start of a receive mark. If the \fBtimestamp\fP is NULL, the current timestamp is used as beginning of mark. The function should be called by client application when pressing a key down (closing a circuit) has been detected by client application. On error the function returns CW_FAILURE, with errno set to ERANGE if the call is directly after another cw_start_receive_tone() call or if an existing received character has not been cleared from the buffer, or EINVAL if the timestamp passed in is invalid. .br Parameter: timestamp - time stamp of "key down" event .br Returns: CW_SUCCESS on success .br Returns: CW_FAILURE otherwise (with errno set) .sp .br .B "int cw_end_receive_tone(const struct timeval *timestamp)" .br Brief: Signal end of mark The function should be called by client application when releasing a key (opening a circuit) has been detected by client application. If the \fBtimestamp\fP is NULL, the current time is used as timestamp of end of mark. On success, the routine adds a dot or dash to the receiver's representation buffer, and returns CW_SUCCESS. On failure, it returns CW_FAIURE, with errno set to: ERANGE if the call was not preceded by a cw_start_receive_tone() call, EINVAL if the timestamp passed in is not valid, ENOENT if function can't tell from duration of the Mark if it's Dot or Dash, ENOMEM if the receiver's representation buffer is full, EAGAIN if the mark was shorter than the threshold for noise and was therefore ignored. .br Parameter: timestamp - time stamp of "key up" event .br Returns: CW_SUCCESS on success .br Returns: CW_FAILURE on failure .sp .br .B "int cw_receive_buffer_dot(const struct timeval *timestamp)" .br Brief: Add a dot to the receiver's representation buffer Documentation for both cw_receive_buffer_dot() and cw_receive_buffer_dash(): Since we can't add a mark to the buffer without any accompanying timing information, the functions accepts \fBtimestamp\fP of the "end of mark" event. If the \fBtimestamp\fP is NULL, the current timestamp is used. These routines are for client code that has already determined whether a dot or dash was received by a method other than calling the routines cw_start_receive_tone() and cw_end_receive_tone(). On success, the relevant mark is added to the receiver's representation buffer. On failure, the routines return CW_FAILURE and set errno: ERANGE if preceded by a cw_start_receive_tone() call with no matching cw_end_receive_tone() or if an error condition currently exists within the receiver's buffer, EINVAL if the timestamp passed in is not valid, ENOMEM if the receiver's representation buffer is full. .br Parameter: timestamp - timestamp of "end of dot" event .br Returns: CW_SUCCESS on success .br Returns: CW_FAILURE on failure .sp .br .B "int cw_receive_buffer_dash(const struct timeval *timestamp)" .br Brief: Add a dash to the receiver's representation buffer See documentation of cw_receive_buffer_dot() for more information. .br Parameter: timestamp - timestamp of "end of dash" event .br Returns: CW_SUCCESS on success .br Returns: CW_FAILURE on failure .sp .br .B "int cw_receive_representation(const struct timeval *timestamp," .br .B " /* out */ char *representation," .br .B " /* out */ bool *is_end_of_word," .br .B " /* out */ bool *is_error)" .br Brief: Get the current buffered representation from the receiver's representation buffer On success the function fills in \fBrepresentation\fP with the contents of the current representation buffer and returns CW_SUCCESS. On failure, it returns CW_FAILURE and sets errno to: ERANGE if not preceded by a cw_end_receive_tone() call, a prior successful cw_receive_representation call, or a prior cw_receive_buffer_dot or cw_receive_buffer_dash, EINVAL if the timestamp passed in is invalid, EAGAIN if the call is made too early to determine whether a complete representation has yet been placed in the buffer (that is, less than the inter-character-space duration elapsed since the last cw_end_receive_tone() or cw_receive_buffer_dot/dash call). This is not a *hard* error, just an information that the caller should try to get the representation later. \fBis_end_of_word\fP indicates that the space after the last mark received is longer that the inter-character-space, so it must be qualified as inter-word-space. \fBis_error\fP indicates that the representation was terminated by an error condition. The function is called periodically (poll()-like function) by client code in hope that at some attempt receiver will be ready to pass \fBrepresentation\fP. The attempt succeeds only if data stream is in "space" state. To mark end of the space, client code has to provide a timestamp (or pass NULL timestamp, the function will get time stamp at function call). The receiver needs to know the "end of space" event - thus the \fBtimestamp\fP parameter. .br Parameter: timestamp - timestamp of event that ends inter-character-space or inter-word-space .br Parameter: representation - buffer for representation (output parameter) .br Parameter: is_end_of_word - buffer for "is end of word" state (output parameter) .br Parameter: is_error - buffer for "error" state (output parameter) .br Returns: CW_SUCCESS on success .br Returns: CW_FAILURE on failure .sp .br .B "int cw_receive_character(const struct timeval *timestamp," .br .B " /* out */ char *c," .br .B " /* out */ bool *is_end_of_word," .br .B " /* out */ bool *is_error)" .br Brief: Get a current character Function returns the character currently stored in receiver's representation buffer. On success the function returns CW_SUCCESS, and fills \fBc\fP with the contents of the current representation buffer, translated into a character. On failure the function returns CW_FAILURE, with errno set to: ERANGE if not preceded by a cw_end_receive_tone() call, a prior successful cw_receive_character() call, or a cw_receive_buffer_dot() or cw_receive_buffer_dash() call, EINVAL if the timestamp passed in is invalid, or EAGAIN if the call is made too early to determine whether a complete character has yet been placed in the buffer (that is, less than the inter-character-space duration elapsed since the last cw_end_receive_tone() or cw_receive_buffer_dot/dash call). ENOENT if character stored in receiver cannot be recognized as valid \fBis_end_of_word\fP indicates that the space after the last mark received is longer that the inter-character-space, so it must be qualified as inter-word-space. \fBis_error\fP indicates that the character was terminated by an error condition. .br Parameter: timestamp - timestamp of event that ends inter-character-space or inter-word-space .br Parameter: c - buffer for character (output parameter) .br Parameter: is_end_of_word - buffer for "is end of word" state (output parameter) .br Parameter: is_error - buffer for "error" state (output parameter) .br Returns: CW_SUCCESS on success .br Returns: CW_FAILURE on failure .sp .br .B "void cw_clear_receive_buffer(void)" .br Brief: Clear receiver's representation buffer Clears the receiver's representation buffer, resets receiver's internal state. This prepares the receiver to receive marks and spaces again. This routine must be called after successful, or terminating, cw_receive_representation() or cw_receive_character() calls, to clear the states and prepare the buffer to receive more marks and spaces. When migrating to libcw2.h, use cw_rec_reset_state() instead of this function. .sp .br .B "int cw_get_receive_buffer_capacity(void)" .br Brief: Get the number of elements (dots/dashes) the receiver's buffer can accommodate The maximum number of elements written out by cw_receive_representation() is the capacity + 1, the extra character being used for the terminating NUL. .br Returns: number of elements that can be stored in receiver's representation buffer .sp .br .B "int cw_get_receive_buffer_length(void)" .br Brief: Get the number of elements (dots/dashes) currently pending in the cw_receiver's representation buffer .br Returns: number of elements in receiver's representation buffer .sp .br .B "void cw_reset_receive(void)" .br Brief: Clear receive data Clear the receiver's representation buffer, statistics, and any retained receiver's state. This function is suitable for calling from an application exit handler. When migrating to libcw2.h, use cw_rec_reset_state() and cw_rec_reset_statistics() instead of this function. .sp .br .B "void cw_register_keying_callback(void (*callback_func)(void*, int), void *callback_arg)" .br Brief: Register external callback function for keying Register a \fBcallback_func\fP function that should be called when a state of a key changes from "key open" to "key closed", or vice-versa. The first argument passed to the registered callback function is the supplied \fBcallback_arg\fP, if any. The second argument passed to registered callback function is the key state: CW_KEY_STATE_CLOSED (one/true) for "key closed", and CW_KEY_STATE_OPEN (zero/false) for "key open". Calling this routine with a NULL function address disables keying callbacks. Any callback supplied will be called in signal handler context (??). .br Parameter: callback_func - callback function to be called on key state changes .br Parameter: callback_arg - first argument to callback_func .sp .br .B "void cw_enable_iambic_curtis_mode_b(void)" .br Brief: Enable iambic Curtis mode B Normally, the iambic keying functions will emulate Curtis 8044 Keyer mode A. In this mode, when both paddles are pressed together, the last dot or dash being sent on release is completed, and nothing else is sent. In mode B, when both paddles are pressed together, the last dot or dash being sent on release is completed, then an opposite element is also sent. Some operators prefer mode B, but timing is more critical in this mode. The default mode is Curtis mode A. .sp .br .B "void cw_disable_iambic_curtis_mode_b(void)" .br See documentation of cw_enable_iambic_curtis_mode_b() for more information .sp .br .B "int cw_get_iambic_curtis_mode_b_state(void)" .br See documentation of cw_enable_iambic_curtis_mode_b() for more information .sp .br .B "int cw_notify_keyer_paddle_event(int dot_paddle_state, int dash_paddle_state)" .br Brief: Inform about changed state of iambic keyer's paddles Function informs the library that the iambic keyer paddles have changed state. The new paddle states are recorded, and if either transition from false to true, paddle latches, for iambic functions, are also set. On success, the routine returns CW_SUCCESS. On failure, it returns CW_FAILURE, with errno set to EBUSY if the tone queue or straight key are using the sound card, console speaker, or keying system. If appropriate, this routine starts the keyer functions sending the relevant element. Element send and timing occurs in the background, so this routine returns almost immediately. .br Parameter: dot_paddle_state .br Parameter: dash_paddle_state .br Returns: CW_SUCCESS on success .br Returns: CW_FAILURE on failure .sp .br .B "int cw_notify_keyer_dot_paddle_event(int dot_paddle_state)" .br Brief: Change state of dot paddle Alter the state of just one of the two iambic keyer paddles. The other paddle state of the paddle pair remains unchanged. See cw_notify_keyer_paddle_event() for details of iambic keyer background processing, and how to check its status. .br Parameter: dot_paddle_state .sp .br .B "int cw_notify_keyer_dash_paddle_event(int dash_paddle_state)" .br See documentation of cw_notify_keyer_dot_paddle_event() for more information .sp .br .B "void cw_get_keyer_paddles(int *dot_paddle_state, int *dash_paddle_state)" .br Brief: Get the current saved states of the two paddles .br Parameter: dot_paddle_state .br Parameter: dash_paddle_state .sp .br .B "void cw_get_keyer_paddle_latches(int *dot_paddle_latch_state, int *dash_paddle_latch_state)" .br Brief: Get the current states of paddle latches Function returns the current saved states of the two paddle latches. A paddle latches is set to true when the paddle state becomes true, and is cleared if the paddle state is false when the element finishes sending. .br Parameter: dot_paddle_latch_state .br Parameter: dash_paddle_latch_state .sp .br .B "bool cw_is_keyer_busy(void)" .br Brief: Check if a keyer is busy .br Returns: true if keyer is busy .br Returns: false if keyer is not busy .sp .br .B "int cw_wait_for_keyer_element(void)" .br Brief: Wait for end of element from the keyer Waits until the end of the current element, dot or dash, from the keyer. .br Returns: CW_SUCCESS on success .br Returns: CW_FAILURE on failure .sp .br .B "int cw_wait_for_keyer(void)" .br Brief: Wait for the current keyer cycle to complete .br Returns: CW_SUCCESS on success .br Returns: CW_FAILURE on failure .sp .br .B "void cw_reset_keyer(void)" .br Brief: Reset iambic keyer data Clear all latches and paddle states of iambic keyer, return to Curtis 8044 Keyer mode A, and return to silence. This function is suitable for calling from an application exit handler. .sp .br .B "int cw_notify_straight_key_event(int key_state)" .br Brief: Inform the library that the straight key has changed state This routine returns CW_SUCCESS on success. On error, it returns CW_FAILURE, with errno set to EBUSY if the tone queue or iambic keyer are using the sound card, console speaker, or keying control system. If \fBkey_state\fP indicates no change of state, the call is ignored. \fBkey_state\fP may be either CW_KEY_STATE_OPEN (false) or CW_KEY_STATE_CLOSED (true). .br Parameter: key_state - state of straight key .sp .br .B "int cw_get_straight_key_state(void)" .br Brief: Get saved state of straight key Returns the current saved state of the straight key. .br Returns: CW_KEY_STATE_CLOSED (true) if the key is down .br Returns: CW_KEY_STATE_OPEN (false) if the key up .sp .br .B "bool cw_is_straight_key_busy(void)" .br Brief: Check if the straight key is busy This routine is just a pseudonym for cw_get_straight_key_state(), and exists to fill a hole in the API naming conventions. .br Returns: true if the straight key is busy .br Returns: false if the straight key is not busy .sp .br .B "void cw_reset_straight_key(void)" .br Brief: Clear the straight key state, and return to silence This function is suitable for calling from an application exit handler. .sp .br .B "bool cw_is_alsa_possible(const char * device_name)" .br Brief: Check if it is possible to open ALSA output with given device name The check consists of two parts: -# whether it's possible to load ALSA shared library, -# whether it's possible to open ALSA device specified by \fBdevice_name\fP If it's possible to use ALSA with given device name, the function leaves library handle (returned by dlopen()) open and some library function symbols loaded, but does not leave any ALSA PCM handle open. Parameter(in): device_name name of ALSA device to be used; if NULL or empty then the function will use library-default device name. .br Returns: true if opening ALSA output succeeded .br Returns: false if opening ALSA output failed .sp .br .B "bool cw_is_console_possible(const char * device_name)" .br Brief: Check if it is possible to open console buzzer output Function does a test opening and test writing to console buzzer device \fBdevice_name\fP, but it closes it before returning. The function tests that the given console buzzer device exists, and that it will accept the KIOCSOUND ioctl. It unconditionally returns false on platforms that do no support the KIOCSOUND ioctl. Call to ioctl will fail if calling code doesn't have root privileges. This is the only place where we ask if KIOCSOUND is defined, so client code must call this function whenever it wants to use console output, as every other function called to perform console operations will happily assume that it is allowed to perform such operations. Parameter(in): device_name name of console buzzer device to be used; if NULL or empty then the function will use library-default device name. .br Returns: true if opening console output succeeded .br Returns: false if opening console output failed .sp .br .B "int cw_get_character_count(void)" .br Brief: Return the number of characters present in main character lookup table Return the number of characters that are known to libcw. The number includes: @li ASCII 7bit letters, @li numerals, @li punctuation, @li ISO 8859-1 accented characters, @li ISO 8859-2 accented characters, @li non-standard procedural signal extensions to standard CW characters. .br Returns: number of characters known to libcw .sp .br .B "void cw_list_characters(char * list)" .br Brief: Get list of characters present in character lookup table Function provides a string containing all of the characters represented in library's lookup table. The list includes: @li ASCII 7bit letters, @li numerals, @li punctuation, @li ISO 8859-1 accented characters, @li ISO 8859-2 accented characters, @li non-standard procedural signal extensions to standard CW characters. \fBlist\fP should be allocated and managed by caller. The length of \fBlist\fP must be at least one greater than the number of characters represented in the character lookup table, returned by cw_get_character_count(). The string placed in \fBlist\fP will be NUL-terminated. Parameter(out): list buffer for string with all characters .sp .br .B "int cw_get_maximum_representation_length(void)" .br Brief: Get length of the longest representation of characters Function returns the string length of the longest representation in the main character lookup table. It is the count of dots and dashes in the longest representation of characters known to libcw (not including terminating NUL). .br Returns: length of the longest representation .sp .br .B "int cw_lookup_character(char character, char * representation)" .br Brief: Get representation of a given character The function is depreciated, use cw_character_to_representation() instead. Return the string representation of a given character \fBcharacter\fP. The routine returns CW_SUCCESS on success, and fills in the string pointer (\fBrepresentation\fP) passed in. On failure, it returns CW_FAILURE and sets errno to ENOENT, indicating that the character \fBcharacter\fP could not be found. The length of \fBrepresentation\fP buffer must be at least one greater than the length of longest representation held in the character lookup table. The largest value of length is returned by cw_get_maximum_representation_length(). Parameter(in): character character to look up Parameter(out): representation pointer to space for representation of character .br Returns: CW_SUCCESS on success .br Returns: CW_FAILURE on failure .sp .br .B "char * cw_character_to_representation(int character)" .br Brief: Get representation of a given character On success return representation of a given character. Returned pointer is owned by caller of the function. On failure function returns NULL and sets errno. ERRNO ENOENT the character could not be found. ERRNO ENOMEM character has been found, but function failed to strdup() representation. Parameter(in): character character to look up .br Returns: pointer to freshly allocated representation on success .br Returns: NULL on failure .sp .br .B "int cw_check_representation(const char * representation)" .br Brief: Check if representation of a character is valid This function is depreciated, use cw_representation_is_valid() instead. Check that the given string is a valid Morse representation. A valid string is one composed of only "." and "-" characters. This means that the function checks only if representation is error-free, and not whether the representation represents existing/defined character. If representation is invalid, function returns CW_FAILURE and sets errno to EINVAL. Parameter(in): representation representation of a character to check .br Returns: CW_SUCCESS on success .br Returns: CW_FAILURE on failure .sp .br .B "bool cw_representation_is_valid(const char * representation)" .br Brief: Check if representation of a character is valid Check that the given string is a valid Morse representation. A valid string is one composed of only "." and "-" characters. This means that the function checks only if representation is error-free, and not whether the representation represents existing/defined character. ERRNO EINVAL representation is invalid Parameter(in): representation representation of a character to check .br Returns: true if representation is valid .br Returns: false if representation is invalid .sp .br .B "int cw_lookup_representation(const char * representation, char * character)" .br Brief: Get the character represented by a given Morse representation This function is depreciated, use cw_representation_to_character() instead. Function checks \fBrepresentation\fP, and if it is valid and represents a known character, function returns CW_SUCCESS. Additionally, if \fBcharacter\fP is non-NULL, function puts the looked up character in \fBcharacter\fP. \fBcharacter\fP should be allocated by caller. Function assumes that \fBcharacter\fP being NULL pointer is a valid situation, and can return CW_SUCCESS in such situation. On error, function returns CW_FAILURE. errno is set to EINVAL if any character of the representation is invalid, or ENOENT to indicate that the character represented by \fBrepresentation\fP could not be found. Parameter(in): representation representation of a character to look up Parameter(out): character location where to put looked up character .br Returns: CW_SUCCESS on success .br Returns: CW_FAILURE on failure .sp .br .B "int cw_representation_to_character(const char * representation)" .br Brief: Return the character represented by a given Morse representation Function checks \fBrepresentation\fP, and if it is valid and represents a known character, function returns the character (a non-zero value). On error, function returns zero (character represented by \fBrepresentation\fP was not found). ERRNO EINVAL \fBrepresentation\fP contains invalid symbol (other than Dots and Dashes) ERRNO ENOENT a character represented by \fBrepresentation\fP could not be found Parameter(in): representation representation of a character to look up .br Returns: non-zero character on success .br Returns: zero on failure .sp .br .B "int cw_get_procedural_character_count(void)" .br Brief: Get number of procedural signals .br Returns: the number of characters stored in the procedural signal expansion lookup table .sp .br .B "void cw_list_procedural_characters(char * list)" .br Brief: Get list of characters for which procedural expansion is available Function copies into preallocated buffer \fBlist\fP a string containing all of the Morse characters for which procedural expansion is available. The length of \fBlist\fP must be at least by one greater than the number of characters represented in the procedural signal expansion lookup table, returned by cw_get_procedural_character_count(). \fBlist\fP buffer is allocated and managed by caller. Parameter(out): list buffer for returned string .sp .br .B "int cw_get_maximum_procedural_expansion_length(void)" .br Brief: Get length of the longest procedural expansion Function returns the string length of the longest expansion in the procedural signal expansion table. .br Returns: the string length of the longest expansion of procedural signals .sp .br .B "int cw_lookup_procedural_character(char character, char *expansion, int * is_usually_expanded)" .br Brief: Get the string expansion of a given Morse code procedural signal character On success the function @li fills \fBexpansion\fP with the string expansion of a given Morse code procedural signal character \fBcharacter\fP; @li sets \fBis_usually_expanded\fP to appropriate value as a display hint for the caller; @li returns CW_SUCCESS. Both \fBexpansion\fP and \fBexpansion\fP must be allocated and managed by caller. They can be NULL, then the function won't attempt to use them. The length of \fBexpansion\fP must be at least by one greater than the longest expansion held in the procedural signal character lookup table, as returned by cw_get_maximum_procedural_expansion_length(). ERRNO ENOENT procedural signal character \fBcharacter\fP cannot be found Parameter(in): character character to look up Parameter(out): expansion buffer to fill with expansion of the character Parameter(out): is_usually_expanded visual hint .br Returns: CW_FAILURE on failure (character cannot be found) .br Returns: CW_SUCCESS on success .sp .br .B "int cw_get_maximum_phonetic_length(void)" .br Brief: Get length of a longest phonetic .br Returns: the string length of the longest phonetic in the phonetics lookup table .sp .br .B "int cw_lookup_phonetic(char character, char * phonetic)" .br Brief: Look up the phonetic of a given character On success the routine copies a phonetic corresponding to \fBcharacter\fP into \fBphonetic\fP. \fBphonetic\fP is managed and owned by caller. It is NOT considered an error if \fBphonetic\fP is NULL. In such case the function will just verify if \fBcharacter\fP can be represented by a phonetic, i.e. if \fBcharacter\fP is a letter. If non-NULL, the size of \fBphonetic\fP must be greater by at least 1 than the longest phonetic held in the phonetic lookup table, as returned by cw_get_maximum_phonetic_length(). ERRNO ENOENT phonetic for given character cannot be found Parameter(in): character character to look up Parameter(out): phonetic buffer for phonetic of a character (may be NULL) .br Returns: CW_SUCCESS on success (phonetic has been found and - if \fBphonetic\fP is non-NULL) has been copied to the buffer .br Returns: CW_FAILURE on failure (phonetic for given character cannot be found) .sp .br .B "bool cw_character_is_valid(char character)" .br Brief: Check if given character is valid Check that a given character is valid, i.e. it is present in library's character-to-representation lookup table and can be represented with Dots and Dashes. Space character (' ') is also considered to be a valid character. ERRNO ENOENT on failure (character is invalid). Notice the difference in errno set by cw_character_is_valid() (ENOENT) and cw_string_is_valid() (EINVAL). This different behaviour goes way back to unixcw-2.3 and is preserved in new versions for backwards compatibility reasons. Parameter(in): character character to check .br Returns: true if character is valid .br Returns: false otherwise .sp .br .B "int cw_check_character(char character)" .br .sp .br .B "bool cw_string_is_valid(const char * string)" .br Brief: Check if all characters in given string are valid Check that each character in the given string is valid and can be converted by libcw to Morse code symbols sent as a Morse character. Space character (' ') is also considered to be a valid character. ERRNO EINVAL on failure (when an invalid character has been found in \fBstring\fP). Notice the difference in errno set by cw_character_is_valid() (ENOENT) and cw_string_is_valid() (EINVAL). This different behaviour goes way back to unixcw-2.3 and is preserved in new versions for backwards compatibility reasons. Parameter(in): string string to check .br Returns: true if all characters in string are valid .br Returns: false otherwise .sp .br .B "int cw_check_string(const char * string)" .br .sp .br .B "void cw_set_debug_flags(uint32_t flags)" .br Brief: Set a value of internal debug flags variable Assign specified value to library's internal debug flags variable. Note that this function doesn't *append* given flag to the variable, it erases existing value and assigns new one. Use cw_get_debug_flags() if you want to OR new flag with existing ones. .br Parameter: flags new value of flags to be assigned to the debug object .sp .br .B "void cw_debug_set_flags(cw_debug_t * debug_object, uint32_t flags)" .br Brief: Set a value of debug flags in given debug variable Assign specified value to given debug variable. Note that this function doesn't *append* given flag to the variable, it erases existing value and assigns new one. Use cw_debug_get_flags() if you want to OR new flag with existing ones. Parameter(in): debug_object debug object for which to set flags Parameter(in): flags new value to be assigned to the object, a sum of one or more of CW_DEBUG_* flags from libcw.h .sp .br .B "uint32_t cw_get_debug_flags(void)" .br Brief: Get library's current debug flags Function returns value of library's internal debug variable, a sum of one or more of CW_DEBUG_* flags from libcw.h. .br Returns: value of library's debug flags variable .sp .br .B "uint32_t cw_debug_get_flags(const cw_debug_t * debug_object)" .br Brief: Get current debug flags from given debug object Function returns value of debug object's debug flags, a sum of one or more of CW_DEBUG_* flags from libcw.h. .br Returns: value of debug object's debug flags .sp .br .B "bool cw_debug_has_flag(const cw_debug_t * debug_object, uint32_t flag)" .br Brief: Check if given debug flag is set Function checks if a specified debug flag is set in given debug object. Parameter(in): debug_object debug object to be checked Parameter(in): flag flag to be checked, one of CW_DEBUG_* flags from libcw.h .br Returns: true if given flag is set .br Returns: false otherwise .sp .br .B "int cw_generator_set_tone_slope(cw_gen_t * gen, int slope_shape, int slope_duration)" .br Brief: Set parameters describing slopes of tones generated by generator Most of variables related to slope of tones is in \fBtone\fP, but there are still some variables that are generator-specific, as they are common for all tones. This function sets two of these generator-specific variables. A: If you pass to function conflicting values of \fBslope_shape\fP and \fBslope_duration\fP, the function will return CW_FAILURE. These conflicting values are rectangular slope shape and larger than zero slope length. You just can't have rectangular slopes that have non-zero length. B: If you pass to function '\-1' as value of both \fBslope_shape\fP and \fBslope_duration\fP, the function won't change any of the related two generator's parameters. C1: If you pass to function '\-1' as value of either \fBslope_shape\fP or \fBslope_duration\fP, the function will attempt to set only this generator's parameter that is different than '\-1'. C2: However, if selected slope shape is rectangular, function will set generator's slope length to zero, even if value of \p slope_duration is '\-1'. D: Notice that the function allows non-rectangular slope shape with zero length of the slopes. The slopes will be non-rectangular, but just unusually short. The function should be called every time one of following parameters change: @li shape of slope, @li duration of slope, @li generator's sample rate, @li generator's volume. There are four supported shapes of slopes: @li linear (the only one supported by libcw until version 4.1.1), @li raised cosine (supposedly the most desired shape), @li sine, @li rectangular. Use CW_TONE_SLOPE_SHAPE_* symbolic names as values of \fBslope_shape\fP. FIXME: first argument of this public function is gen, but no function provides access to generator variable. Parameter(in): gen generator for which to set tone slope parameters Parameter(in): slope_shape shape of slope: linear, raised cosine, sine, rectangular Parameter(in): slope_duration duration of slope [microseconds] .br Returns: CW_SUCCESS on success .br Returns: CW_FAILURE on failure .sp .br .B "bool cw_is_null_possible(__attribute__((unused)) const char * device_name)" .br Brief: Check if it is possible to open Null sound output Parameter(in): device_name name of Null device to be used. Value is ignored for Null sound system. .br Returns: true it's always possible to write to Null device .sp .br .B "bool cw_is_oss_possible(const char * device_name)" .br Brief: Check if it is possible to open OSS output with given device name Function does a test opening and test configuration of OSS output, but it closes it before returning. Parameter(in): device_name name of OSS device to be used; if NULL or empty then the function will use library-default device name. .br Returns: true if opening OSS output succeeded .br Returns: false if opening OSS output failed .sp .br .B "bool cw_is_pa_possible(const char * device_name)" .br Brief: Check if it is possible to open PulseAudio output with given device name Function first tries to load PulseAudio library, and then does a test opening of PulseAudio output, but it closes it before returning. Parameter(in): device_name name of PulseAudio device to be used; if NULL then the function will use library-default device name. .br Returns: true if opening PulseAudio output succeeded .br Returns: false if opening PulseAudio output failed .sp .br .B "void cw_block_callback(int block)" .br Brief: Block the callback from being called Function blocks the callback from being called for a critical section of caller code if \fBblock\fP is true, and unblocks the callback if \fBblock\fP is false. Function works by blocking SIGALRM; a block should always be matched by an unblock, otherwise the tone queue will suspend forever. .br Parameter: block - pass 1 to block SIGALRM, and 0 to unblock it .sp .br .B "int cw_register_signal_handler(int signal_number, void (*callback_func)(int))" .br Brief: Register a signal handler and optional callback function for given signal number On receipt of that signal, all library features will be reset to their default states. Following the reset, if \fBcallback_func\fP is a function pointer, the function is called; if it is SIG_DFL, the library calls exit(); and if it is SIG_IGN, the library returns from the signal handler. This is a convenience function for clients that need to clean up library on signals, with either exit, continue, or an additional function call; in effect, a wrapper round a restricted form of sigaction. The \fBsignal_number\fP argument indicates which signal to catch. On problems errno is set to EINVAL if \fBsignal_number\fP is invalid or if a handler is already installed for that signal, or to the sigaction error code. .br Parameter: signal_number .br Parameter: callback_func .br Returns: CW_SUCCESS - if the signal handler installs correctly .br Returns: CW_FAILURE - on errors or problems .sp .br .B "int cw_unregister_signal_handler(int signal_number)" .br Brief: Unregister a signal handler interception Function removes a signal handler interception previously registered with cw_register_signal_handler(). .br Parameter: signal_number .br Returns: true if the signal handler uninstalls correctly .br Returns: false otherwise (with errno set to EINVAL or to the sigaction error code) .sp .br .B "int cw_version(void)" .br Brief: Return version number of libcw library Return the version number of the library. Version numbers (major and minor) are returned as an int, composed of major_version << 16 | minor_version. .br Returns: library's major and minor version number encoded as single int .sp .br .B "void cw_license(void)" .br Brief: Print libcw's license text to stdout Function prints to stdout information about libcw version, followed by short text presenting libcw's copyright and license notice. .sp .br .B "const char * cw_get_audio_system_label(int sound_system)" .br Brief: Get a readable label of given sound system The function returns one of following strings: None, Null, Console, OSS, ALSA, PulseAudio, Soundcard Returned pointer is owned and managed by the library. *const cw_get_audio_system_label(...)"? Parameter(in): sound_system ID of sound system .br Returns: sound system's label .sp .br .B "void cw_get_speed_limits(int * min_speed, int * max_speed)" .br Brief: Get speed limits Get (through function's arguments) limits on speed of Morse code that are supported by libcw. See CW_SPEED_MIN and CW_SPEED_MAX in libcw.h for values. Any of functions two arguments can be NULL - function won't update value of that argument. Parameter(out): min_speed minimal allowed speed Parameter(out): max_speed maximal allowed speed .sp .br .B "void cw_get_frequency_limits(int * min_frequency, int * max_frequency)" .br Brief: Get frequency limits Get (through function's arguments) limits on frequency that are supported by libcw. See CW_FREQUENCY_MIN and CW_FREQUENCY_MAX in libcw.h for values. Any of functions two arguments can be NULL - function won't update value of that argument. Parameter(out): min_frequency minimal allowed frequency Parameter(out): max_frequency maximal allowed frequency .sp .br .B "void cw_get_volume_limits(int * min_volume, int * max_volume)" .br Brief: Get volume limits Get (through function's arguments) limits on volume of sound supported by libcw and generated by generator. See CW_VOLUME_MIN and CW_VOLUME_MAX in libcw.h for values. Any of functions two arguments can be NULL - function won't update value of that argument. Parameter(out): min_volume minimal allowed volume Parameter(out): max_volume maximal allowed volume .sp .br .B "void cw_get_gap_limits(int * min_gap, int * max_gap)" .br Brief: Get gap limits Get (through function's arguments) limits on gap in cw signal supported by libcw. See CW_GAP_MIN and CW_GAP_MAX in libcw.h for values. Any of functions two arguments can be NULL - function won't update value of that argument. Parameter(out): min_gap minimal allowed gap Parameter(out): max_gap maximal allowed gap .sp .br .B "void cw_get_tolerance_limits(int * min_tolerance, int * max_tolerance)" .br Brief: Get tolerance limits Get (through function's arguments) limits on "tolerance" parameter supported by libcw. See CW_TOLERANCE_MIN and CW_TOLERANCE_MAX in libcw.h for values. Any of functions two arguments can be NULL - function won't update value of that argument. Parameter(out): min_tolerance minimal allowed tolerance Parameter(out): max_tolerance maximal allowed tolerance .sp .br .B "void cw_get_weighting_limits(int * min_weighting, int * max_weighting)" .br Brief: Get weighting limits Get (through function's arguments) limits on "weighting" parameter supported by libcw. See CW_WEIGHTING_MIN and CW_WEIGHTING_MAX in libcw.h for values. Any of functions two arguments can be NULL - function won't update value of that argument. Parameter(out): min_weighting minimal allowed weighting Parameter(out): max_weighting maximal allowed weighting .sp .br .B "void cw_complete_reset(void)" .br Brief: Reset all library features to their default states Clears the tone queue, receive buffers and retained state information, any current keyer activity, and any straight key activity, returns to silence, and closes soundcard and console devices. This function is suitable for calling from an application exit handler. .PP .\" .\" .\" .SH NOTES .\" Despite the fact that this manual page constantly and consistently refers to Morse code elements as dots and dashes, DO NOT think in these terms when trying to learn Morse code. Always think of them as 'dit's and 'dah's. .PP .B libcw uses system itimers for its internal timing. On most UNIX flavours, itimers are not guaranteed to signal a program exactly at the specified time, and they generally offer a resolution only as good as the normal system 'clock tick' resolution. An itimer SIGALRM usually falls on a system clock tick, making it accurate to no better than 10mS on a typical 100Hz kernel. .PP The effect of this is that an itimer period is generally either exactly as specified, or, more likely, slightly longer. At higher WPM settings, the cumulative effect of this affects timing accuracy, because at higher speeds, there are fewer 10mS clock ticks in a dot period. For example, at 12 WPM, the dot length is 100mS, enough to contain five kernel clock ticks; at 60 WPM, the dot length is 20mS, or just two kernel clock ticks. So at higher speeds, the effect of itimer resolutions becomes more pronounced. .PP .\" .\" .\" .SH SEE ALSO .\" Man pages for \fBcw\fP(7,LOCAL), \fBcw\fP(1,LOCAL), \fBcwgen\fP(1,LOCAL), \fBcwcp\fP(1,LOCAL), and \fBxcwcp\fP(1,LOCAL). .\"