Changeset 92b638c in mainline


Ignore:
Timestamp:
2012-08-30T11:41:48Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5eed99d
Parents:
ed3816d
Message:

audio, sb16: Add and implement API for playback/capture with or without fragments.

Location:
uspace
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/drec/drec.c

    red3816d r92b638c  
    124124        const unsigned frames = rec->buffer.size /
    125125            (BUFFER_PARTS * channels * pcm_sample_format_size(format));
    126         int ret = audio_pcm_start_capture(rec->device,
     126        int ret = audio_pcm_start_capture_fragment(rec->device,
    127127            frames, channels, sampling_rate, format);
    128128        if (ret != EOK) {
  • uspace/app/wavplay/dplay.c

    red3816d r92b638c  
    113113                   buffer_part, pb->source);
    114114                if (bytes == 0) {
    115                         audio_pcm_stop_playback(pb->device);
     115                        audio_pcm_last_playback_fragment(pb->device);
    116116                }
    117117                bzero(pb->buffer.position + bytes, buffer_part - bytes);
     
    148148        const unsigned frames = pb->buffer.size /
    149149            (BUFFER_PARTS * channels * pcm_sample_format_size(format));
    150         ret = audio_pcm_start_playback(pb->device, frames, channels,
     150        ret = audio_pcm_start_playback_fragment(pb->device, frames, channels,
    151151            sampling_rate, format);
    152152        if (ret != EOK) {
  • uspace/drv/audio/sb16/dsp.c

    red3816d r92b638c  
    403403                return EINVAL;
    404404
     405        if (dsp->state != DSP_READY && dsp->state != DSP_STOPPED)
     406                return EINVAL;
     407
    405408        /* Check supported parameters */
    406409        ddf_log_debug("Requested playback: %u frames, %uHz, %s, %u channel(s).",
     
    444447}
    445448
    446 int sb_dsp_stop_playback(sb_dsp_t *dsp)
    447 {
    448         assert(dsp);
    449         if (dsp->state != DSP_PLAYBACK_NOEVENTS &&
    450             dsp->state != DSP_PLAYBACK_ACTIVE_EVENTS)
    451                 return EINVAL;
    452 
    453         sb_dsp_write(dsp, DMA_16B_EXIT);
    454         ddf_log_debug("Stopping playback on buffer.");
    455         sb_dsp_change_state(dsp, DSP_PLAYBACK_TERMINATE);
    456         return EOK;
     449int sb_dsp_stop_playback(sb_dsp_t *dsp, bool immediate)
     450{
     451        assert(dsp);
     452        if ((dsp->state == DSP_PLAYBACK_NOEVENTS ||
     453            dsp->state == DSP_PLAYBACK_ACTIVE_EVENTS) &&
     454            immediate)
     455        {
     456                sb_dsp_write(dsp, DMA_16B_PAUSE);
     457                sb_dsp_reset(dsp);
     458                ddf_log_debug("Stopped playback");
     459                sb_dsp_change_state(dsp, DSP_STOPPED);
     460                return EOK;
     461        }
     462        if (dsp->state == DSP_PLAYBACK_ACTIVE_EVENTS)
     463        {
     464                /* Stop after current fragment */
     465                assert(!immediate);
     466                sb_dsp_write(dsp, DMA_16B_EXIT);
     467                ddf_log_debug("Last playback fragment");
     468                sb_dsp_change_state(dsp, DSP_PLAYBACK_TERMINATE);
     469                return EOK;
     470        }
     471        return EINVAL;
    457472}
    458473
     
    462477        assert(dsp);
    463478        if (!dsp->buffer.data)
     479                return EINVAL;
     480        if (dsp->state != DSP_READY && dsp->state != DSP_STOPPED)
    464481                return EINVAL;
    465482
     
    503520}
    504521
    505 int sb_dsp_stop_capture(sb_dsp_t *dsp)
    506 {
    507         assert(dsp);
    508         if (dsp->state != DSP_CAPTURE_NOEVENTS &&
    509             dsp->state != DSP_CAPTURE_ACTIVE_EVENTS)
    510                 return EINVAL;
    511 
    512         sb_dsp_write(dsp, DMA_16B_EXIT);
    513         ddf_log_debug("Stopped capture");
    514         sb_dsp_change_state(dsp, DSP_CAPTURE_TERMINATE);
    515         return EOK;
     522int sb_dsp_stop_capture(sb_dsp_t *dsp, bool immediate)
     523{
     524        assert(dsp);
     525        if ((dsp->state == DSP_CAPTURE_NOEVENTS ||
     526            dsp->state == DSP_CAPTURE_ACTIVE_EVENTS) &&
     527            immediate)
     528        {
     529                sb_dsp_write(dsp, DMA_16B_PAUSE);
     530                sb_dsp_reset(dsp);
     531                ddf_log_debug("Stopped capture fragment");
     532                sb_dsp_change_state(dsp, DSP_STOPPED);
     533                return EOK;
     534        }
     535        if (dsp->state == DSP_CAPTURE_ACTIVE_EVENTS)
     536        {
     537                /* Stop after current fragment */
     538                assert(!immediate);
     539                sb_dsp_write(dsp, DMA_16B_EXIT);
     540                ddf_log_debug("Last capture fragment");
     541                sb_dsp_change_state(dsp, DSP_CAPTURE_TERMINATE);
     542                return EOK;
     543        }
     544        return EINVAL;
    516545}
    517546/**
  • uspace/drv/audio/sb16/dsp.h

    red3816d r92b638c  
    9090int sb_dsp_start_playback(sb_dsp_t *dsp, unsigned frames,
    9191    unsigned channels, unsigned sample_rate, pcm_sample_format_t format);
    92 int sb_dsp_stop_playback(sb_dsp_t *dsp);
     92int sb_dsp_stop_playback(sb_dsp_t *dsp, bool immediate);
    9393int sb_dsp_start_capture(sb_dsp_t *dsp, unsigned frames,
    9494    unsigned channels, unsigned sample_rate, pcm_sample_format_t format);
    95 int sb_dsp_stop_capture(sb_dsp_t *dsp);
     95int sb_dsp_stop_capture(sb_dsp_t *dsp, bool immediate);
    9696
    9797#endif
  • uspace/drv/audio/sb16/pcm_iface.c

    red3816d r92b638c  
    9696}
    9797
    98 static int sb_stop_playback(ddf_fun_t *fun)
     98static int sb_stop_playback(ddf_fun_t *fun, bool immediate)
    9999{
    100         return sb_dsp_stop_playback(fun_to_dsp(fun));
     100        return sb_dsp_stop_playback(fun_to_dsp(fun), immediate);
    101101}
    102102
     
    108108}
    109109
    110 static int sb_stop_capture(ddf_fun_t *fun)
     110static int sb_stop_capture(ddf_fun_t *fun, bool immediate)
    111111{
    112         return sb_dsp_stop_capture(fun_to_dsp(fun));
     112        return sb_dsp_stop_capture(fun_to_dsp(fun), immediate);
    113113}
    114114
  • uspace/lib/drv/generic/remote_audio_pcm.c

    red3816d r92b638c  
    342342 * 0 to turn off event generation.
    343343 */
    344 int audio_pcm_start_playback(audio_pcm_sess_t *sess, unsigned frames,
     344int audio_pcm_start_playback_fragment(audio_pcm_sess_t *sess, unsigned frames,
    345345    unsigned channels, unsigned sample_rate, pcm_sample_format_t format)
    346346{
     
    357357        return ret;
    358358}
    359 
    360 /**
    361  * Stop current playback.
     359/**
     360 * Stops playback after current fragment.
     361 *
     362 * @param sess Audio device session.
     363 *
     364 * @return Error code.
     365 */
     366int audio_pcm_last_playback_fragment(audio_pcm_sess_t *sess)
     367{
     368        async_exch_t *exch = async_exchange_begin(sess);
     369        const int ret = async_req_2_0(exch,
     370            DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
     371            IPC_M_AUDIO_PCM_STOP_PLAYBACK, false);
     372        async_exchange_end(exch);
     373        return ret;
     374}
     375
     376/**
     377 * Start playback on buffer from the current position.
     378 *
     379 * @param sess Audio device session.
     380 * @param channels Number of channels.
     381 * @param sample_rate Sampling rate (for one channel).
     382 * @param format Sample format.
     383 *
     384 * @return Error code.
     385 */
     386int audio_pcm_start_playback(audio_pcm_sess_t *sess,
     387    unsigned channels, unsigned sample_rate, pcm_sample_format_t format)
     388{
     389        return audio_pcm_start_playback_fragment(
     390            sess, 0, channels, sample_rate, format);
     391}
     392
     393/**
     394 * Immediately stops current playback.
    362395 *
    363396 * @param sess Audio device session.
     
    368401{
    369402        async_exch_t *exch = async_exchange_begin(sess);
    370         const int ret = async_req_1_0(exch,
    371             DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
    372             IPC_M_AUDIO_PCM_STOP_PLAYBACK);
    373         async_exchange_end(exch);
    374         return ret;
    375 }
    376 
    377 /**
    378  * Start capture on buffer from position 0.
     403        const int ret = async_req_2_0(exch,
     404            DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
     405            IPC_M_AUDIO_PCM_STOP_PLAYBACK, true);
     406        async_exchange_end(exch);
     407        return ret;
     408}
     409
     410/**
     411 * Start capture on buffer from the current position.
    379412 *
    380413 * @param sess Audio device session.
     
    389422 * 0 to turn off event generation.
    390423 */
    391 int audio_pcm_start_capture(audio_pcm_sess_t *sess, unsigned frames,
     424int audio_pcm_start_capture_fragment(audio_pcm_sess_t *sess, unsigned frames,
    392425    unsigned channels, unsigned sample_rate, pcm_sample_format_t format)
    393426{
     
    405438
    406439/**
    407  * Stop current playback.
     440 * Start capture on buffer from the current position.
     441 *
     442 * @param sess Audio device session.
     443 * @param channels Number of channels.
     444 * @param sample_rate Sampling rate (for one channel).
     445 * @param format Sample format.
     446 *
     447 * @return Error code.
     448 */
     449int audio_pcm_start_capture(audio_pcm_sess_t *sess,
     450    unsigned channels, unsigned sample_rate, pcm_sample_format_t format)
     451{
     452        return audio_pcm_start_capture_fragment(
     453            sess, 0, channels, sample_rate, format);
     454}
     455
     456/**
     457 * Stops capture at the end of current fragment.
     458 *
     459 * Won't work if capture was started with fragment size 0.
     460 * @param sess Audio device session.
     461 *
     462 * @return Error code.
     463 */
     464int audio_pcm_last_capture_fragment(audio_pcm_sess_t *sess)
     465{
     466        async_exch_t *exch = async_exchange_begin(sess);
     467        const int ret = async_req_2_0(exch,
     468            DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
     469            IPC_M_AUDIO_PCM_STOP_CAPTURE, false);
     470        async_exchange_end(exch);
     471        return ret;
     472}
     473
     474/**
     475 * Immediately stops current capture.
    408476 *
    409477 * @param sess Audio device session.
     
    414482{
    415483        async_exch_t *exch = async_exchange_begin(sess);
    416         const int ret = async_req_1_0(exch,
    417             DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE), IPC_M_AUDIO_PCM_STOP_CAPTURE);
     484        const int ret = async_req_2_0(exch,
     485            DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
     486            IPC_M_AUDIO_PCM_STOP_CAPTURE, true);
    418487        async_exchange_end(exch);
    419488        return ret;
     
    648717{
    649718        const audio_pcm_iface_t *pcm_iface = iface;
     719        const bool immediate = DEV_IPC_GET_ARG1(*call);
    650720
    651721        const int ret = pcm_iface->stop_playback ?
    652             pcm_iface->stop_playback(fun) : ENOTSUP;
     722            pcm_iface->stop_playback(fun, immediate) : ENOTSUP;
    653723        async_answer_0(callid, ret);
    654724}
     
    674744{
    675745        const audio_pcm_iface_t *pcm_iface = iface;
     746        const bool immediate = DEV_IPC_GET_ARG1(*call);
    676747
    677748        const int ret = pcm_iface->stop_capture ?
    678             pcm_iface->stop_capture(fun) : ENOTSUP;
     749            pcm_iface->stop_capture(fun, immediate) : ENOTSUP;
    679750        async_answer_0(callid, ret);
    680751}
  • uspace/lib/drv/include/audio_pcm_iface.h

    red3816d r92b638c  
    8181int audio_pcm_release_buffer(audio_pcm_sess_t *);
    8282
    83 int audio_pcm_start_playback(audio_pcm_sess_t *, unsigned,
     83int audio_pcm_start_playback_fragment(audio_pcm_sess_t *, unsigned,
     84    unsigned, unsigned, pcm_sample_format_t);
     85int audio_pcm_last_playback_fragment(audio_pcm_sess_t *);
     86
     87int audio_pcm_start_playback(audio_pcm_sess_t *,
    8488    unsigned, unsigned, pcm_sample_format_t);
    8589int audio_pcm_stop_playback(audio_pcm_sess_t *);
    8690
    87 int audio_pcm_start_capture(audio_pcm_sess_t *, unsigned,
     91int audio_pcm_start_capture_fragment(audio_pcm_sess_t *, unsigned,
     92    unsigned, unsigned, pcm_sample_format_t);
     93int audio_pcm_last_capture_fragment(audio_pcm_sess_t *);
     94
     95int audio_pcm_start_capture(audio_pcm_sess_t *,
    8896    unsigned, unsigned, pcm_sample_format_t);
    8997int audio_pcm_stop_capture(audio_pcm_sess_t *);
     
    102110        int (*start_playback)(ddf_fun_t *, unsigned,
    103111            unsigned, unsigned, pcm_sample_format_t);
    104         int (*stop_playback)(ddf_fun_t *);
     112        int (*stop_playback)(ddf_fun_t *, bool);
    105113        int (*start_capture)(ddf_fun_t *, unsigned,
    106114            unsigned, unsigned, pcm_sample_format_t);
    107         int (*stop_capture)(ddf_fun_t *);
     115        int (*stop_capture)(ddf_fun_t *, bool);
    108116} audio_pcm_iface_t;
    109117
  • uspace/srv/audio/hound/audio_device.c

    red3816d r92b638c  
    112112                const unsigned frames = dev->buffer.size /
    113113                    (BUFFER_PARTS * pcm_format_frame_size(&dev->sink.format));
    114                 ret = audio_pcm_start_playback(dev->sess, frames,
     114                ret = audio_pcm_start_playback_fragment(dev->sess, frames,
    115115                    dev->sink.format.channels, dev->sink.format.sampling_rate,
    116116                    dev->sink.format.sample_format);
     
    155155                const unsigned frames = dev->buffer.size /
    156156                    (BUFFER_PARTS * pcm_format_frame_size(&dev->sink.format));
    157                 ret = audio_pcm_start_capture(dev->sess, frames,
     157                ret = audio_pcm_start_capture_fragment(dev->sess, frames,
    158158                    dev->sink.format.channels, dev->sink.format.sampling_rate,
    159159                    dev->sink.format.sample_format);
Note: See TracChangeset for help on using the changeset viewer.