/* Generates a constant square wave sound with a given frequency in Hertz for a duration in milliseconds */ void beep_play(unsigned int frequency, unsigned int duration, unsigned int amplitude) { mixer_channel_stop(PCM_MIXER_CHAN_BEEP); if (frequency == 0 || duration == 0 || amplitude == 0) return; if (amplitude > INT16_MAX) amplitude = INT16_MAX; /* Setup the parameters for the square wave generator */ beep_phase = 0; beep_step = 0xffffffffu / NATIVE_FREQUENCY * frequency; beep_count = NATIVE_FREQUENCY / 1000 * duration; #ifdef BEEP_GENERIC beep_amplitude = amplitude; #else /* Optimized routines do XOR with phase sign bit in both channels at once */ beep_amplitude = amplitude | (amplitude << 16); /* Word:|AMP16|AMP16| */ #endif /* If it fits - avoid cb overhead */ const void *start; size_t size; /* Generate first frame here */ beep_get_more(&start, &size); mixer_channel_set_amplitude(PCM_MIXER_CHAN_BEEP, MIX_AMP_UNITY); mixer_channel_play_data(PCM_MIXER_CHAN_BEEP, beep_count ? beep_get_more : NULL, start, size); }
static int dissect_beep_more(tvbuff_t *tvb, int offset, proto_tree *tree) { proto_item *hidden_item; int ret = 0; switch (beep_get_more(tvb_get_guint8(tvb, offset))) { case BEEP_COMPLETE: if (tree) { hidden_item = proto_tree_add_boolean(tree, hf_beep_complete, tvb, offset, 1, TRUE); PROTO_ITEM_SET_HIDDEN(hidden_item); proto_tree_add_text(tree, tvb, offset, 1, "More: Complete"); } ret = 0; break; case BEEP_INTERMEDIATE: if (tree) { hidden_item = proto_tree_add_boolean(tree, hf_beep_intermediate, tvb, offset, 1, TRUE); PROTO_ITEM_SET_HIDDEN(hidden_item); proto_tree_add_text(tree, tvb, offset, 1, "More: Intermediate"); } ret = 1; break; default: if (tree) { hidden_item = proto_tree_add_boolean(tree, hf_beep_proto_viol, tvb, offset, 1, TRUE); PROTO_ITEM_SET_HIDDEN(hidden_item); proto_tree_add_text(tree, tvb, offset, 1, "PROTOCOL VIOLATION: Expected More Flag (* or .)"); } ret = -1; break; } return ret; }