Audio
The 825 Gen2 has an audio line out port. Powered speakers may be plugged into this port to allow for high quality stereo audio output. The audio output is independent from the beeper.
The command line utility aplay may be used to play wav files to the audio output, for example: (For this example audio files are placed on a flash drive in directory wav_files auto mounted as /run/media/sda1)
card825gen2:~$ aplay /run/media/sda1/wav_files/BOUNCEIN.WAV Playing WAVE '/run/media/sda1/wav_files/BOUNCEIN.WAV' : Signed 16 bit Little Endian, Rate 22050 Hz, Mono card825gen2:~$ aplay /run/media/sda1/wav_files/BOING.WAV Playing WAVE '/run/media/sda1/wav_files/BOING.WAV' : Signed 16 bit Little Endian, Rate 22025 Hz, Mono card825gen2:~$ aplay /run/media/sda1/wav_files/BOUNCE.WAV Playing WAVE '/run/media/sda1/wav_files/BOUNCE.WAV' : Signed 16 bit Little Endian, Rate 22025 Hz, Mono card825gen2:~$ aplay /run/media/sda1/wav_files/HAPPY.WAV Playing WAVE '/run/media/sda1/wav_files/HAPPY.WAV' : Signed 16 bit Little Endian, Rate 22050 Hz, Mono card825gen2:~$ aplay /run/media/sda1/wav_files/MELT.WAV Playing WAVE '/run/media/sda1/wav_files/MELT.WAV' : Signed 16 bit Little Endian, Rate 22050 Hz, Mono
Gstreamer may be used to play an mp3 audio file:
card825gen2:~$ gst-launch-1.0 playbin uri=file:///run/media/Data-sda1/sample-12s.mp3
Apps may be written to output audio by using system calls to perform commands such as above. However, it would be better to use gstreamer library calls in the app.
This is an example app:
#include <gst/gst.h> #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { GstElement *pipeline; GstBus *bus; GstMessage *msg; GError *error = NULL; // Check command-line arguments if (argc != 2) { fprintf(stderr, "Usage: %s <MP3 file path>\n", argv[0]); return EXIT_FAILURE; } // Initialize GStreamer gst_init(&argc, &argv); // Create the pipeline using playbin (handles decoding automatically) char *pipeline_desc; pipeline_desc = g_strdup_printf("playbin uri=file://%s", argv[1]); pipeline = gst_parse_launch(pipeline_desc, &error); g_free(pipeline_desc); if (!pipeline) { fprintf(stderr, "Failed to create pipeline: %s\n", error ? error->message : "Unknown error"); if (error) g_error_free(error); return EXIT_FAILURE; } // Start playing gst_element_set_state(pipeline, GST_STATE_PLAYING); // Wait until error or EOS (End Of Stream) bus = gst_element_get_bus(pipeline); msg = gst_bus_timed_pop_filtered( bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS ); // Handle the message if (msg != NULL) { GError *err; gchar *debug_info; switch (GST_MESSAGE_TYPE(msg)) { case GST_MESSAGE_ERROR: gst_message_parse_error(msg, &err, &debug_info); fprintf(stderr, "Error: %s\n", err->message); fprintf(stderr, "Debug info: %s\n", debug_info ? debug_info : "none"); g_clear_error(&err); g_free(debug_info); break; case GST_MESSAGE_EOS: printf("Playback finished.\n"); break; default: // Should not reach here break; } gst_message_unref(msg); } // Free resources gst_object_unref(bus); gst_element_set_state(pipeline, GST_STATE_NULL); gst_object_unref(pipeline); return EXIT_SUCCESS; }
Also refer to the ID Storage app source code class CGStreamer. This has the ability to queue audio files to play in a background thread.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/cardinal.gif)