| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2003-2006, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: $ |
|---|
| 11 | * $brcm_Revision: $ |
|---|
| 12 | * $brcm_Date: $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: $ |
|---|
| 19 | * |
|---|
| 20 | ***************************************************************************/ |
|---|
| 21 | |
|---|
| 22 | #ifndef BSETTOP_PCM_H__ |
|---|
| 23 | #define BSETTOP_PCM_H__ |
|---|
| 24 | |
|---|
| 25 | #include "bsettop_types.h" |
|---|
| 26 | |
|---|
| 27 | #ifdef __cplusplus |
|---|
| 28 | extern "C" |
|---|
| 29 | { |
|---|
| 30 | #endif |
|---|
| 31 | |
|---|
| 32 | /*=*********************************** |
|---|
| 33 | The PCM interface is used to write PCM data to a PCM playback |
|---|
| 34 | channel. |
|---|
| 35 | |
|---|
| 36 | PCM playback can be used for sound effects or music (often with a |
|---|
| 37 | CPU-based decoder for formats like MP3). |
|---|
| 38 | |
|---|
| 39 | The API is the minimal needed for streaming data. The BSEAV team also |
|---|
| 40 | provides a file-based API located in BSEAV/lib/pcmfile. The file-based |
|---|
| 41 | API includes WAV file support. |
|---|
| 42 | **************************************/ |
|---|
| 43 | |
|---|
| 44 | #define BPCM_PLAYBACK_CHANNELS 1 |
|---|
| 45 | |
|---|
| 46 | /* |
|---|
| 47 | Summary: |
|---|
| 48 | PCM playback state enumerations. |
|---|
| 49 | Description: |
|---|
| 50 | These are the different states that the PCM playback channels can be in. |
|---|
| 51 | */ |
|---|
| 52 | typedef enum pcm_play_state |
|---|
| 53 | { |
|---|
| 54 | ePCM_PLAY_STATE_CLOSED, |
|---|
| 55 | ePCM_PLAY_STATE_OPENED, |
|---|
| 56 | ePCM_PLAY_STATE_STARTED, |
|---|
| 57 | ePCM_PLAY_STATE_STOPPED, |
|---|
| 58 | } pcm_play_state_t; |
|---|
| 59 | |
|---|
| 60 | /* |
|---|
| 61 | Summary: |
|---|
| 62 | PCM playback handle returned by bpcm_play_open. |
|---|
| 63 | Description: |
|---|
| 64 | The implementation of the handle is private. |
|---|
| 65 | */ |
|---|
| 66 | typedef struct bpcm_play *bpcm_play_t; |
|---|
| 67 | /* |
|---|
| 68 | Summary: |
|---|
| 69 | PCM audio settings which are used in bpcm_play_settings and bpcm_record_settings. |
|---|
| 70 | Description: |
|---|
| 71 | The total bitrate of the PCM stream is: |
|---|
| 72 | bits_per_second = bits_per_sample * sample_rate * channels. |
|---|
| 73 | */ |
|---|
| 74 | typedef struct bpcm_settings { |
|---|
| 75 | unsigned bits_per_sample; /* Either 8 or 16 */ |
|---|
| 76 | unsigned sample_rate; /* Samples per channel per second. Either 32000, 44100, 48000. */ |
|---|
| 77 | unsigned channels; /* Either 1 (mono) or 2 (stereo) */ |
|---|
| 78 | } bpcm_settings; |
|---|
| 79 | |
|---|
| 80 | /* |
|---|
| 81 | Summary: |
|---|
| 82 | PCM play settings passed to bpcm_play_start. |
|---|
| 83 | Description: |
|---|
| 84 | Even though there is no more data than just bpcm_settings, we've added this |
|---|
| 85 | to support future API extensions. |
|---|
| 86 | */ |
|---|
| 87 | typedef struct bpcm_play_settings { |
|---|
| 88 | bpcm_settings pcm; /* PCM format */ |
|---|
| 89 | bsettop_callback callback; /* This callback notifies the user that there is |
|---|
| 90 | space available in the pcm playback buffer. The user may call bpcm_play_get_buffer |
|---|
| 91 | but should not call bpcm_play_write_complete. After receiving a callback, |
|---|
| 92 | no additional callback will be received until bpcm_play_write_complete |
|---|
| 93 | is called. */ |
|---|
| 94 | void *callback_context; /* User defined context which is passed into the |
|---|
| 95 | above callback function. */ |
|---|
| 96 | } bpcm_play_settings; |
|---|
| 97 | |
|---|
| 98 | /* |
|---|
| 99 | Summary: |
|---|
| 100 | Open a PCM playback channel. |
|---|
| 101 | |
|---|
| 102 | */ |
|---|
| 103 | bpcm_play_t bpcm_play_open( |
|---|
| 104 | bobject_t id /* id corresponds to the pcm playback channel. */ |
|---|
| 105 | ); |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | /* |
|---|
| 109 | Summary: |
|---|
| 110 | Close a PCM playback channel. |
|---|
| 111 | Description: |
|---|
| 112 | Playback must already be stopped. |
|---|
| 113 | */ |
|---|
| 114 | |
|---|
| 115 | void bpcm_play_close( |
|---|
| 116 | bpcm_play_t pcmplay |
|---|
| 117 | ); |
|---|
| 118 | |
|---|
| 119 | /* |
|---|
| 120 | Summary: |
|---|
| 121 | Start playing PCM audio. |
|---|
| 122 | */ |
|---|
| 123 | |
|---|
| 124 | bresult bpcm_play_start( |
|---|
| 125 | bpcm_play_t pcmplay, |
|---|
| 126 | bdisplay_t display, /* which output to play to */ |
|---|
| 127 | bpcm_play_settings *settings |
|---|
| 128 | ); |
|---|
| 129 | |
|---|
| 130 | /* |
|---|
| 131 | Summary: |
|---|
| 132 | Status information returned by bpcm_play_get_status |
|---|
| 133 | */ |
|---|
| 134 | typedef struct bpcm_play_status { |
|---|
| 135 | unsigned int index; /* Which pcm playback channel is playing? */ |
|---|
| 136 | pcm_play_state_t state; /* The state of the pcm playback channel. */ |
|---|
| 137 | unsigned queued_bytes; /* Number of bytes waiting to be played. */ |
|---|
| 138 | unsigned long fifo_size; /* Size in bytes of the pcm buffer */ |
|---|
| 139 | void *buffer_base; /* Pointer to the base of the pcm buffer. |
|---|
| 140 | This can be used for calculating your exact position |
|---|
| 141 | in the buffer for alignment considerations. */ |
|---|
| 142 | } bpcm_play_status; |
|---|
| 143 | |
|---|
| 144 | /* |
|---|
| 145 | Summary: |
|---|
| 146 | Get status information. |
|---|
| 147 | */ |
|---|
| 148 | |
|---|
| 149 | bresult bpcm_play_get_status( |
|---|
| 150 | bpcm_play_t pcmplay, |
|---|
| 151 | bpcm_play_status *status |
|---|
| 152 | ); |
|---|
| 153 | |
|---|
| 154 | /** |
|---|
| 155 | Summary: |
|---|
| 156 | Get space available in the pcm playback buffer. |
|---|
| 157 | |
|---|
| 158 | Description: |
|---|
| 159 | This is a non-destructive call. You can call it as many times as you want. |
|---|
| 160 | After writing data into the buffer, you should call bpcm_play_write_complete |
|---|
| 161 | to report how much of the buffer was used. On loop around length will be limited |
|---|
| 162 | to the buffer size minus the write offset then the next call will return the delta |
|---|
| 163 | between the read and write pointers. |
|---|
| 164 | **/ |
|---|
| 165 | |
|---|
| 166 | bresult bpcm_play_get_buffer( |
|---|
| 167 | bpcm_play_t pcmplay, |
|---|
| 168 | void **data, |
|---|
| 169 | size_t *length |
|---|
| 170 | ); |
|---|
| 171 | |
|---|
| 172 | /** |
|---|
| 173 | Summary: |
|---|
| 174 | update the ringbuffer write offset |
|---|
| 175 | |
|---|
| 176 | Description call to update the rinbuffer write offset. On loop around |
|---|
| 177 | of the ringbuffer the amount_written should not extend past the end of buffer. |
|---|
| 178 | This matches the behaivior of bpcm_play_get_buffer. |
|---|
| 179 | **/ |
|---|
| 180 | |
|---|
| 181 | bresult bpcm_play_write_complete( |
|---|
| 182 | bpcm_play_t pcmplay, |
|---|
| 183 | size_t amount_written |
|---|
| 184 | ); |
|---|
| 185 | |
|---|
| 186 | /* |
|---|
| 187 | Summary: |
|---|
| 188 | Stop PCM playback |
|---|
| 189 | */ |
|---|
| 190 | bresult bpcm_play_stop( |
|---|
| 191 | bpcm_play_t pcmplay |
|---|
| 192 | ); |
|---|
| 193 | |
|---|
| 194 | /* |
|---|
| 195 | Summary: |
|---|
| 196 | Required to initialize the bpcm_settings structure. |
|---|
| 197 | */ |
|---|
| 198 | void bpcm_play_settings_init( |
|---|
| 199 | bpcm_play_settings *settings, /* [out] */ |
|---|
| 200 | bpcm_play_t pcmplay /* required for possible resource-dependent defaults */ |
|---|
| 201 | ); |
|---|
| 202 | |
|---|
| 203 | #ifdef CONFIG_PCM_TEST |
|---|
| 204 | void bpcm_play_test(); |
|---|
| 205 | #endif |
|---|
| 206 | |
|---|
| 207 | #ifdef __cplusplus |
|---|
| 208 | } |
|---|
| 209 | #endif |
|---|
| 210 | |
|---|
| 211 | #endif /* BSETTOP_PCM_H__ */ |
|---|