Changeset 0b4f060 in mainline
- Timestamp:
- 2011-10-24T21:36:52Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6233c4e
- Parents:
- 7785e951
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/audio/sb16/dsp.c
r7785e951 r0b4f060 34 34 35 35 #include <libarch/ddi.h> 36 #include <libarch/barrier.h> 36 37 #include <str_error.h> 37 38 … … 41 42 #include "dsp_commands.h" 42 43 #include "dsp.h" 44 45 #define PLAYBACK_16BIT 0x10 46 #define PLAYBACK_STEREO 0x20 43 47 44 48 #define BUFFER_SIZE (PAGE_SIZE / 4) … … 139 143 } 140 144 /*----------------------------------------------------------------------------*/ 145 static inline size_t sample_count(uint8_t mode, size_t byte_count) 146 { 147 if (mode & PLAYBACK_16BIT) { 148 return byte_count / 2; 149 } 150 return byte_count; 151 } 152 /*----------------------------------------------------------------------------*/ 141 153 int sb_dsp_init(sb_dsp_t *dsp, sb16_regs_t *regs) 142 154 { … … 195 207 /* This is the last block */ 196 208 memcpy(dsp->buffer.position, dsp->playing.position, remain_size); 209 write_barrier(); 197 210 dsp->playing.position += remain_size; 198 211 dsp->buffer.position += remain_size; 212 const size_t samples = 213 sample_count(dsp->playing.mode, remain_size); 199 214 sb_dsp_write(dsp, SINGLE_DMA_16B_DA); 200 215 sb_dsp_write(dsp, dsp->playing.mode); 201 sb_dsp_write(dsp, ( remain_size- 1) & 0xff);202 sb_dsp_write(dsp, ( remain_size- 1) >> 8);216 sb_dsp_write(dsp, (samples - 1) & 0xff); 217 sb_dsp_write(dsp, (samples - 1) >> 8); 203 218 return; 204 219 } 205 220 ddf_log_note("Playing full block.\n"); 206 221 memcpy(dsp->buffer.position, dsp->playing.position, PLAY_BLOCK_SIZE); 222 write_barrier(); 207 223 dsp->playing.position += PLAY_BLOCK_SIZE; 208 224 dsp->buffer.position += PLAY_BLOCK_SIZE; … … 236 252 /*----------------------------------------------------------------------------*/ 237 253 int sb_dsp_play(sb_dsp_t *dsp, const uint8_t *data, size_t size, 238 uint16_t sampling_rate, unsigned channels, unsigned bit_depth)254 uint16_t sampling_rate, unsigned channels, unsigned sample_size) 239 255 { 240 256 assert(dsp); … … 243 259 244 260 /* Check supported parameters */ 245 if ( bit_depth != 8 && bit_depth!= 16)261 if (sample_size != 8 && sample_size != 16) 246 262 return ENOTSUP; 247 263 if (channels != 1 && channels != 2) … … 258 274 size < BUFFER_SIZE ? size : BUFFER_SIZE; 259 275 260 261 276 dsp->playing.data = data; 262 277 dsp->playing.position = data + copy_size; 263 278 dsp->playing.size = size; 264 dsp->playing.mode = 265 (bit_depth == 16 ? 0x10 : 0) | (channels == 2 ? 0x20 : 0); 266 ddf_log_debug("Setting DSP mode %hhx.\n", dsp->playing.mode); 267 268 ddf_log_debug("Playing sound: %zu(%zu) bytes.\n", play_size, size); 279 dsp->playing.mode = 0; 280 if (sample_size == 16) 281 dsp->playing.mode |= PLAYBACK_16BIT; 282 if (channels == 2) 283 dsp->playing.mode |= PLAYBACK_STEREO; 284 285 const size_t samples = sample_count(dsp->playing.mode, play_size); 286 287 ddf_log_debug("Playing sound(%hhx): %zu(%zu) bytes => %zu samples.\n", 288 dsp->playing.mode, play_size, size, samples); 289 269 290 memcpy(dsp->buffer.data, dsp->playing.data, copy_size); 291 write_barrier(); 270 292 271 293 sb_dsp_write(dsp, SET_SAMPLING_RATE_OUTPUT); … … 273 295 sb_dsp_write(dsp, sampling_rate & 0xff); 274 296 275 ddf_log_debug("S et sampling rate%hhx:%hhx.\n",297 ddf_log_debug("Sampling rate: %hhx:%hhx.\n", 276 298 sampling_rate >> 8, sampling_rate & 0xff); 277 299 … … 282 304 } 283 305 sb_dsp_write(dsp, dsp->playing.mode); 284 sb_dsp_write(dsp, ( play_size- 1) & 0xff);285 sb_dsp_write(dsp, ( play_size- 1) >> 8);306 sb_dsp_write(dsp, (samples - 1) & 0xff); 307 sb_dsp_write(dsp, (samples - 1) >> 8); 286 308 287 309 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.