Changeset 1240bb9 in mainline


Ignore:
Timestamp:
2012-07-12T18:20:45Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d01e635
Parents:
992ef56
Message:

Use named audio events.

audio/sb16: dsp uses more detailed status (not just playing/not-playing).
app/drec: Fix parameter order in.

Location:
uspace
Files:
5 edited

Legend:

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

    r992ef56 r1240bb9  
    9191                ipc_call_t call;
    9292                ipc_callid_t callid = async_get_call(&call);
    93                 if (IPC_GET_IMETHOD(call) != IPC_FIRST_USER_METHOD) {
    94                         printf("Unknown event.\n");
     93                switch(IPC_GET_IMETHOD(call)) {
     94                case PCM_EVENT_PLAYBACK_DONE:
     95                        printf("+");
     96                        async_answer_0(callid, EOK);
    9597                        break;
     98                case PCM_EVENT_PLAYBACK_TERMINATED:
     99                        printf("\nPlayback terminated\n");
     100                        fibril_mutex_lock(&pb->mutex);
     101                        pb->playing = false;
     102                        fibril_condvar_signal(&pb->cv);
     103                        async_answer_0(callid, EOK);
     104                        fibril_mutex_unlock(&pb->mutex);
     105                        return;
     106                default:
     107                        printf("Unknown event %d.\n", IPC_GET_IMETHOD(call));
     108                        async_answer_0(callid, ENOTSUP);
     109                        continue;
     110
    96111                }
    97                 printf("+");
    98112                const size_t bytes = fread(pb->buffer.position, sizeof(uint8_t),
    99113                   buffer_part, pb->source);
     
    103117                if (pb->buffer.position >= (pb->buffer.base + pb->buffer.size))
    104118                        pb->buffer.position = pb->buffer.base;
    105                 async_answer_0(callid, EOK);
    106119                if (bytes == 0) {
     120                        fibril_mutex_lock(&pb->mutex);
    107121                        pb->playing = false;
    108122                        fibril_condvar_signal(&pb->cv);
     123                        fibril_mutex_unlock(&pb->mutex);
    109124                }
    110125        }
     
    138153
    139154        audio_pcm_stop_playback(pb->device, pb->buffer.id);
    140         fibril_condvar_wait(&pb->cv, &pb->mutex);
     155        for (pb->playing = true; pb->playing;
     156                fibril_condvar_wait(&pb->cv, &pb->mutex));
     157        fibril_mutex_unlock(&pb->mutex);
    141158        printf("\n");
    142159}
  • uspace/app/drec/drec.c

    r992ef56 r1240bb9  
    8989                ipc_call_t call;
    9090                ipc_callid_t callid = async_get_call(&call);
    91                 if (IPC_GET_IMETHOD(call) != IPC_FIRST_USER_METHOD) {
    92                         printf("Unknown event.\n");
     91                switch(IPC_GET_IMETHOD(call)) {
     92                case PCM_EVENT_RECORDING_DONE:
     93                        printf("+");
     94                        async_answer_0(callid, EOK);
    9395                        break;
     96                case PCM_EVENT_RECORDING_TERMINATED:
     97                        printf("\nRecording terminated\n");
     98                        return;
     99                default:
     100                        printf("Unknown event %d.\n", IPC_GET_IMETHOD(call));
     101                        async_answer_0(callid, ENOTSUP);
     102                        continue;
     103
    94104                }
    95105                const size_t bytes = fwrite(rec->buffer.position,
     
    207217        };
    208218        fwrite(&header, sizeof(header), 1, rec.file);
    209         record(&rec, sampling_rate, channels, format);
     219        record(&rec, channels, sampling_rate, format);
    210220        fclose(rec.file);
    211221
  • uspace/drv/audio/sb16/dsp.c

    r992ef56 r1240bb9  
    3333 */
    3434
     35#include <bool.h>
    3536#include <devman.h>
    3637#include <device/hw_res.h>
     
    3839#include <libarch/barrier.h>
    3940#include <str_error.h>
    40 #include <bool.h>
     41#include <audio_pcm_iface.h>
    4142
    4243#include "dma.h"
     
    162163        dsp->event_exchange = NULL;
    163164        dsp->sb_dev = dev;
     165        dsp->status = DSP_STOPPED;
    164166        sb_dsp_reset(dsp);
    165167        /* "DSP takes about 100 microseconds to initialize itself" */
     
    188190        assert(dsp);
    189191        if (dsp->event_exchange) {
    190                 async_msg_0(dsp->event_exchange, IPC_FIRST_USER_METHOD);
     192                switch (dsp->status) {
     193                case DSP_PLAYBACK:
     194                        async_msg_0(dsp->event_exchange,
     195                            PCM_EVENT_PLAYBACK_DONE);
     196                        break;
     197                case DSP_RECORDING:
     198                        async_msg_0(dsp->event_exchange,
     199                            PCM_EVENT_RECORDING_DONE);
     200                        break;
     201                default:
     202                case DSP_STOPPED:
     203                        ddf_log_warning("Interrupt while DSP stopped and "
     204                            "event exchange present. Terminating exchange");
     205                        async_exchange_end(dsp->event_exchange);
     206                        dsp->event_exchange = NULL;
     207                }
    191208        } else {
    192209                ddf_log_warning("Interrupt with no event consumer.");
     
    316333            sampling_rate / (dsp->active.samples * channels));
    317334
    318         dsp->active.playing = true;
     335        dsp->status = DSP_PLAYBACK;
    319336
    320337        return EOK;
     
    326343        if (id != BUFFER_ID)
    327344                return ENOENT;
     345        sb_dsp_write(dsp, DMA_16B_EXIT);
     346        ddf_log_debug("Stopping playback on buffer %u.", id);
     347        async_msg_0(dsp->event_exchange, PCM_EVENT_PLAYBACK_TERMINATED);
    328348        async_exchange_end(dsp->event_exchange);
    329         sb_dsp_write(dsp, DMA_16B_EXIT);
     349        dsp->event_exchange = NULL;
    330350        return EOK;
    331351}
     
    389409            "(~1/%u sec)", dsp->active.samples,
    390410            sampling_rate / (dsp->active.samples * channels));
    391         dsp->active.playing = false;
     411        dsp->status = DSP_RECORDING;
    392412
    393413        return EOK;
     
    399419        if (id != BUFFER_ID)
    400420                return ENOENT;
     421        sb_dsp_write(dsp, DMA_16B_EXIT);
     422        ddf_log_debug("Stopping playback on buffer %u.", id);
     423        async_msg_0(dsp->event_exchange, PCM_EVENT_RECORDING_TERMINATED);
    401424        async_exchange_end(dsp->event_exchange);
    402         sb_dsp_write(dsp, DMA_16B_EXIT);
     425        dsp->event_exchange = NULL;
    403426        return EOK;
    404427}
  • uspace/drv/audio/sb16/dsp.h

    r992ef56 r1240bb9  
    5757                uint8_t mode;
    5858                uint16_t samples;
    59                 bool playing;
    6059        } active;
     60        enum {
     61                DSP_PLAYBACK,
     62                DSP_RECORDING,
     63                DSP_STOPPED,
     64        } status;
    6165        async_sess_t *event_session;
    6266        async_exch_t *event_exchange;
  • uspace/lib/drv/include/audio_pcm_iface.h

    r992ef56 r1240bb9  
    4343#include "ddf/driver.h"
    4444
     45enum {
     46        PCM_EVENT_PLAYBACK_DONE = IPC_FIRST_USER_METHOD,
     47        PCM_EVENT_RECORDING_DONE,
     48        PCM_EVENT_PLAYBACK_TERMINATED,
     49        PCM_EVENT_RECORDING_TERMINATED
     50};
     51
     52
    4553int audio_pcm_get_info_str(async_exch_t *, const char **);
    4654int audio_pcm_get_buffer(async_exch_t *, void **, size_t *, unsigned *,
Note: See TracChangeset for help on using the changeset viewer.