📄 audio__if_8h.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>BlueLab: audio_if.h File Reference</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.3.8 --><div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a></div><h1>audio_if.h File Reference</h1>The global definitions for the audio subsystem. <a href="#_details">More...</a><p><h2>Defines</h2><ul><li>#define <a class="el" href="audio__if_8h.html#a0">AUDIO_END</a> ((<a class="el" href="audio__if_8h.html#a5">audio_note</a>) AUDIO_SEQ_END)<li>#define <a class="el" href="audio__if_8h.html#a1">AUDIO_TEMPO</a>(t) ((<a class="el" href="audio__if_8h.html#a5">audio_note</a>) (AUDIO_SEQ_TEMPO | (t)))<li>#define <a class="el" href="audio__if_8h.html#a2">AUDIO_VOLUME</a>(v) ((<a class="el" href="audio__if_8h.html#a5">audio_note</a>) (AUDIO_SEQ_VOLUME | (v)))<li>#define <a class="el" href="audio__if_8h.html#a3">AUDIO_TIMBRE</a>(t) ((<a class="el" href="audio__if_8h.html#a5">audio_note</a>) (AUDIO_SEQ_TIMBRE | (<a class="el" href="csrtypes_8h.html#a4">uint16</a>) audio_tone_##t))<li>#define <a class="el" href="audio__if_8h.html#a4">AUDIO_DECAY</a>(d) ((<a class="el" href="audio__if_8h.html#a5">audio_note</a>) (AUDIO_SEQ_DECAY | (d)))</ul><h2>Typedefs</h2><ul><li>typedef this_struct_doesnt_exist * <a class="el" href="audio__if_8h.html#a5">audio_note</a><li>typedef enum <a class="el" href="audio__if_8h.html#a14">audio_tone_type_enum</a> <a class="el" href="audio__if_8h.html#a6">audio_tone_type</a></ul><h2>Enumerations</h2><ul><li>enum <a class="el" href="audio__if_8h.html#a14">audio_tone_type_enum</a> { <br> <a class="el" href="audio__if_8h.html#a14a7">audio_tone_sine</a>, <br> <a class="el" href="audio__if_8h.html#a14a8">audio_tone_square</a>, <br> <a class="el" href="audio__if_8h.html#a14a9">audio_tone_saw</a>, <br> <a class="el" href="audio__if_8h.html#a14a10">audio_tone_triangle</a>, <br> <a class="el" href="audio__if_8h.html#a14a11">audio_tone_triangle2</a>, <br> <a class="el" href="audio__if_8h.html#a14a12">audio_tone_clipped_sine</a>, <br> <a class="el" href="audio__if_8h.html#a14a13">audio_tone_plucked</a><br> }</ul><hr><a name="_details"></a><h2>Detailed Description</h2>The global definitions for the audio subsystem. <p><dl compact><dt><b>PCM Audio</b></dt><dd></dd></dl>BlueCore chips are provided with an advanced PCM Audio subsystem, and this can be accessed by user code running on the VM. The PCM system allows for the playing of tones of any pitch, or for the playing of samples. In this way maximum flexibility is maintained.<p>The PCM subsystem is accessed by creating a stream from either an array of 'audio_note's, or a sample in the file system, and then connecting this stream to a PCM sink stream.<p>For example:<p>StreamConnect(StreamAudioSource(ringtone), StreamPcmSink(0));<p>StreamConnect(StreamFileSource(FileFind(FILE_ROOT, "sample", sizeof("sample")-1)), StreamPcmSink(0));<p><dl compact><dt><b>Playing Ringtones</b></dt><dd></dd></dl>When playing ringtones from an array of audio_notes, each element in the array can specify either a note value, or a command. This file defines the macros that can be used to easily build these arrays.<p>The 'audio_note' type is defined in such a way that it is possible to store either sixteen bit numbers or pointers.<p>Notes are specified with either the <a class="el" href="audio__notes_8h.html#a197">AUDIO_NOTE(note, duration)</a> or <a class="el" href="audio__notes_8h.html#a198">AUDIO_NOTE_TIE(note, duration)</a> macros. The parameters to these two macros are the same, and their operation is very similar. The 'note' parameter specifies the pitch of the note that will be played. It should be one of the constants defined in the 'audio_notes.h' file. The macro contains token-pasting, so we only need to specify the last few characters of the note value (ie. C3). The 'duration' parameter gives the duration of the note in musical terms, and should also be one of the defines from the 'audio_notes.h' file.<p><a class="el" href="audio__notes_8h.html#a197">AUDIO_NOTE(C5, CROTCHET)</a> Play a middle C<p><a class="el" href="audio__notes_8h.html#a197">AUDIO_NOTE(D7, SEMIBREVE)</a> Play a D two octaves up, for longer<p>So to play a simple ringtone we first declare the audio_note array:<p>static const audio_note ringtone[] = { <a class="el" href="audio__if_8h.html#a3">AUDIO_TIMBRE(sine)</a>, <a class="el" href="audio__notes_8h.html#a197">AUDIO_NOTE(C5, MINIM)</a>, <a class="el" href="audio__if_8h.html#a3">AUDIO_TIMBRE(square)</a>, <a class="el" href="audio__notes_8h.html#a197">AUDIO_NOTE(C5, MINIM)</a>, <a class="el" href="audio__if_8h.html#a3">AUDIO_TIMBRE(saw)</a>, <a class="el" href="audio__notes_8h.html#a197">AUDIO_NOTE(C5, MINIM)</a>, <a class="el" href="audio__if_8h.html#a3">AUDIO_TIMBRE(triangle)</a>, <a class="el" href="audio__notes_8h.html#a197">AUDIO_NOTE(C5, MINIM)</a>, <a class="el" href="audio__if_8h.html#a3">AUDIO_TIMBRE(triangle2)</a>, <a class="el" href="audio__notes_8h.html#a197">AUDIO_NOTE(C5, MINIM)</a>, <a class="el" href="audio__if_8h.html#a3">AUDIO_TIMBRE(clipped_sine)</a>, <a class="el" href="audio__notes_8h.html#a197">AUDIO_NOTE(C5, MINIM)</a>, <a class="el" href="audio__if_8h.html#a3">AUDIO_TIMBRE(plucked)</a>, <a class="el" href="audio__notes_8h.html#a197">AUDIO_NOTE(C5, MINIM)</a>, AUDIO_END };<p>and then connect it to a suitable Sink. In this case a PCM port.<p>StreamConnect(StreamAudioSource(ringtone), StreamPcmSink(0));<p><dl compact><dt><b>Playing samples</b></dt><dd></dd></dl>Applications can play samples by utilising the flash file system as follows.<p><ul><li>Ensure the sample is in the correct format for the codec being used (e.g. 8/13/16bit).</li><li>Place the sample in the flash file system by adding it to the 'image' directory of the project.</li><li>Use FileFind to get the index of the file. FILE_INDEX index = FileFind(FILE_ROOT, "sample", sizeof("sample")-1))</li><li>Use StreamFileSource to get a Source from the file index. Source file_src = StreamFileSource(index);</li><li>Use StreamConnect to connect the source to the desired Sink. StreamConnect(file_src, StreamPcmSink(0));</li></ul><p>The following sample macros have been removed from BlueLab.<p><ul><li>AUDIO_APP_SAMPLE_8BIT(loc, siz)</li><li>AUDIO_APP_SAMPLE_16BIT(loc, siz)</li><li>AUDIO_APP_SAMPLE_8BIT_PARTIAL(loc, start, len)</li><li>AUDIO_APP_SAMPLE_16BIT_PARTIAL(loc, start, len)</li></ul><p><dl compact><dt><b>Other information:</b></dt><dd></dd></dl>There may be a short gap in the sequence between moving from one note or sample from the next. The precise lengths of these gaps may vary from one build to the next and between multiple renditions of the same sequence.<hr><h2>Define Documentation</h2><a class="anchor" name="a0" doxytag="audio_if.h::AUDIO_END" ></a><p><table class="mdTable" width="100%" cellpadding="2" cellspacing="0"> <tr> <td class="mdRow"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> #define AUDIO_END ((<a class="el" href="audio__if_8h.html#a5">audio_note</a>) AUDIO_SEQ_END) </td> </tr> </table> </td> </tr></table><table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td><p>This command must be given at the end of a sequence. It causes the sequence to be stopped. All sequences must end this way. </td> </tr></table><a class="anchor" name="a1" doxytag="audio_if.h::AUDIO_TEMPO" ></a><p><table class="mdTable" width="100%" cellpadding="2" cellspacing="0"> <tr> <td class="mdRow"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> #define AUDIO_TEMPO </td> <td class="md" valign="top">( </td> <td class="md" nowrap valign="top">t </td> <td class="mdname1" valign="top" nowrap> </td> <td class="md" valign="top"> ) </td> <td class="md" nowrap> ((<a class="el" href="audio__if_8h.html#a5">audio_note</a>) (AUDIO_SEQ_TEMPO | (t)))</td> </tr> </table> </td> </tr></table><table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td><p>This command is used to change the tempo of the sequence. A twelve-bit value is given as the new tempo in crotchets (quarter notes) per minute. The default is 120. </td> </tr></table><a class="anchor" name="a2" doxytag="audio_if.h::AUDIO_VOLUME" ></a><p><table class="mdTable" width="100%" cellpadding="2" cellspacing="0"> <tr> <td class="mdRow"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> #define AUDIO_VOLUME </td> <td class="md" valign="top">( </td> <td class="md" nowrap valign="top">v </td> <td class="mdname1" valign="top" nowrap> </td> <td class="md" valign="top"> ) </td> <td class="md" nowrap> ((<a class="el" href="audio__if_8h.html#a5">audio_note</a>) (AUDIO_SEQ_VOLUME | (v)))</td> </tr> </table> </td> </tr></table><table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td><p>This command sets a new volume. All notes played after this command are played with the specified volume, that is, currently playing notes are not affected. The default is maximum volume. </td> </tr></table><a class="anchor" name="a3" doxytag="audio_if.h::AUDIO_TIMBRE" ></a><p><table class="mdTable" width="100%" cellpadding="2" cellspacing="0"> <tr>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -