2007-10-06 22:27:27 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 by Linus Nielsen Feltzing
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2007-10-06 22:27:27 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#ifndef PCM_PLAYBACK_H
|
|
|
|
#define PCM_PLAYBACK_H
|
|
|
|
|
2010-05-06 21:04:40 +00:00
|
|
|
#include <string.h> /* size_t */
|
2007-10-06 22:27:27 +00:00
|
|
|
|
2008-10-14 11:43:32 +00:00
|
|
|
#define DMA_REC_ERROR_DMA (-1)
|
|
|
|
#ifdef HAVE_SPDIF_REC
|
|
|
|
#define DMA_REC_ERROR_SPDIF (-2)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/** Warnings **/
|
|
|
|
/* pcm (dma) buffer has overflowed */
|
|
|
|
#define PCMREC_W_PCM_BUFFER_OVF 0x00000001
|
|
|
|
/* encoder output buffer has overflowed */
|
|
|
|
#define PCMREC_W_ENC_BUFFER_OVF 0x00000002
|
|
|
|
/** Errors **/
|
|
|
|
/* failed to load encoder */
|
|
|
|
#define PCMREC_E_LOAD_ENCODER 0x80001000
|
|
|
|
/* error originating in encoder */
|
|
|
|
#define PCMREC_E_ENCODER 0x80002000
|
|
|
|
/* filename queue has desynced from stream markers */
|
|
|
|
#define PCMREC_E_FNQ_DESYNC 0x80004000
|
|
|
|
/* I/O error has occurred */
|
|
|
|
#define PCMREC_E_IO 0x80008000
|
|
|
|
#ifdef DEBUG
|
2010-11-13 17:49:45 +00:00
|
|
|
/* encoder has written past end of allocated space */
|
2008-10-14 11:43:32 +00:00
|
|
|
#define PCMREC_E_CHUNK_OVF 0x80010000
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2007-10-06 22:27:27 +00:00
|
|
|
/** RAW PCM routines used with playback and recording **/
|
|
|
|
|
|
|
|
/* Typedef for registered callback */
|
2010-05-24 16:42:32 +00:00
|
|
|
typedef void (*pcm_play_callback_type)(unsigned char **start,
|
2007-10-06 22:27:27 +00:00
|
|
|
size_t *size);
|
2010-05-24 16:42:32 +00:00
|
|
|
typedef void (*pcm_rec_callback_type)(int status, void **start, size_t *size);
|
2007-10-06 22:27:27 +00:00
|
|
|
|
2010-06-26 10:07:17 +00:00
|
|
|
/* set the pcm frequency - use values in hw_sampr_list
|
|
|
|
* when CONFIG_SAMPR_TYPES is #defined, or-in SAMPR_TYPE_* fields with
|
|
|
|
* frequency value. SAMPR_TYPE_PLAY is 0 and the default if none is
|
|
|
|
* specified. */
|
|
|
|
#ifdef CONFIG_SAMPR_TYPES
|
|
|
|
#ifdef SAMPR_TYPE_REC
|
|
|
|
unsigned int pcm_sampr_type_rec_to_play(unsigned int samplerate);
|
|
|
|
#endif
|
|
|
|
#endif /* CONFIG_SAMPR_TYPES */
|
|
|
|
|
2008-12-12 11:01:07 +00:00
|
|
|
void pcm_set_frequency(unsigned int samplerate);
|
2007-10-06 22:27:27 +00:00
|
|
|
/* apply settings to hardware immediately */
|
|
|
|
void pcm_apply_settings(void);
|
|
|
|
|
|
|
|
/** RAW PCM playback routines **/
|
|
|
|
|
|
|
|
/* Reenterable locks for locking and unlocking the playback interrupt */
|
|
|
|
void pcm_play_lock(void);
|
|
|
|
void pcm_play_unlock(void);
|
|
|
|
|
2010-05-27 12:00:29 +00:00
|
|
|
void pcm_init(void) INIT_ATTR;
|
2010-06-11 14:39:35 +00:00
|
|
|
void pcm_postinit(void);
|
2007-10-06 22:27:27 +00:00
|
|
|
|
|
|
|
/* This is for playing "raw" PCM data */
|
2010-05-24 16:42:32 +00:00
|
|
|
void pcm_play_data(pcm_play_callback_type get_more,
|
2007-10-06 22:27:27 +00:00
|
|
|
unsigned char* start, size_t size);
|
|
|
|
|
|
|
|
void pcm_calculate_peaks(int *left, int *right);
|
2010-02-10 19:44:11 +00:00
|
|
|
const void* pcm_get_peak_buffer(int* count);
|
2007-10-06 22:27:27 +00:00
|
|
|
size_t pcm_get_bytes_waiting(void);
|
|
|
|
|
|
|
|
void pcm_play_stop(void);
|
|
|
|
void pcm_play_pause(bool play);
|
|
|
|
bool pcm_is_paused(void);
|
|
|
|
bool pcm_is_playing(void);
|
|
|
|
|
|
|
|
/** The following are for internal use between pcm.c and target-
|
|
|
|
specific portion **/
|
|
|
|
|
2010-05-24 16:42:32 +00:00
|
|
|
/* Called by the bottom layer ISR when more data is needed. Returns non-
|
|
|
|
* zero size if more data is to be played. Setting start to NULL
|
|
|
|
* forces stop. */
|
|
|
|
void pcm_play_get_more_callback(void **start, size_t *size);
|
|
|
|
|
2007-10-06 22:27:27 +00:00
|
|
|
extern unsigned long pcm_curr_sampr;
|
2008-12-12 11:01:07 +00:00
|
|
|
extern unsigned long pcm_sampr;
|
|
|
|
extern int pcm_fsel;
|
2007-10-06 22:27:27 +00:00
|
|
|
|
2009-02-08 22:32:41 +00:00
|
|
|
#ifdef HAVE_PCM_DMA_ADDRESS
|
|
|
|
void * pcm_dma_addr(void *addr);
|
|
|
|
#endif
|
|
|
|
|
2010-05-24 16:42:32 +00:00
|
|
|
extern volatile bool pcm_playing;
|
|
|
|
extern volatile bool pcm_paused;
|
2007-10-06 22:27:27 +00:00
|
|
|
|
|
|
|
void pcm_play_dma_lock(void);
|
|
|
|
void pcm_play_dma_unlock(void);
|
2010-05-27 12:00:29 +00:00
|
|
|
void pcm_play_dma_init(void) INIT_ATTR;
|
2007-10-06 22:27:27 +00:00
|
|
|
void pcm_play_dma_start(const void *addr, size_t size);
|
|
|
|
void pcm_play_dma_stop(void);
|
|
|
|
void pcm_play_dma_pause(bool pause);
|
|
|
|
const void * pcm_play_dma_get_peak_buffer(int *count);
|
|
|
|
|
2008-12-12 11:01:07 +00:00
|
|
|
void pcm_dma_apply_settings(void);
|
|
|
|
|
2007-10-06 22:27:27 +00:00
|
|
|
#ifdef HAVE_RECORDING
|
|
|
|
|
|
|
|
/** RAW PCM recording routines **/
|
|
|
|
|
|
|
|
/* Reenterable locks for locking and unlocking the recording interrupt */
|
|
|
|
void pcm_rec_lock(void);
|
|
|
|
void pcm_rec_unlock(void);
|
|
|
|
|
|
|
|
/* Initialize pcm recording interface */
|
|
|
|
void pcm_init_recording(void);
|
2010-05-13 20:39:03 +00:00
|
|
|
/* Uninitialize pcm recording interface */
|
2007-10-06 22:27:27 +00:00
|
|
|
void pcm_close_recording(void);
|
|
|
|
|
|
|
|
/* Start recording "raw" PCM data */
|
2010-05-24 16:42:32 +00:00
|
|
|
void pcm_record_data(pcm_rec_callback_type more_ready,
|
2007-10-06 22:27:27 +00:00
|
|
|
void *start, size_t size);
|
|
|
|
|
|
|
|
/* Stop tranferring data into supplied buffer */
|
|
|
|
void pcm_stop_recording(void);
|
|
|
|
|
2008-12-13 06:01:08 +00:00
|
|
|
/* Is pcm currently recording? */
|
|
|
|
bool pcm_is_recording(void);
|
|
|
|
|
2010-05-24 16:42:32 +00:00
|
|
|
/* Called by bottom layer ISR when transfer is complete. Returns non-zero
|
|
|
|
* size if successful. Setting start to NULL forces stop. */
|
|
|
|
void pcm_rec_more_ready_callback(int status, void **start, size_t *size);
|
2007-10-06 22:27:27 +00:00
|
|
|
|
|
|
|
void pcm_calculate_rec_peaks(int *left, int *right);
|
|
|
|
|
|
|
|
/** The following are for internal use between pcm.c and target-
|
|
|
|
specific portion **/
|
|
|
|
/* DMA transfer in is currently active */
|
2010-05-24 16:42:32 +00:00
|
|
|
extern volatile bool pcm_recording;
|
2007-10-06 22:27:27 +00:00
|
|
|
|
|
|
|
/* APIs implemented in the target-specific portion */
|
|
|
|
void pcm_rec_dma_init(void);
|
|
|
|
void pcm_rec_dma_close(void);
|
|
|
|
void pcm_rec_dma_start(void *addr, size_t size);
|
2010-05-12 14:05:36 +00:00
|
|
|
void pcm_rec_dma_record_more(void *start, size_t size);
|
2007-10-06 22:27:27 +00:00
|
|
|
void pcm_rec_dma_stop(void);
|
2010-05-12 14:05:36 +00:00
|
|
|
const void * pcm_rec_dma_get_peak_buffer(void);
|
2007-10-06 22:27:27 +00:00
|
|
|
|
|
|
|
#endif /* HAVE_RECORDING */
|
|
|
|
|
|
|
|
#endif /* PCM_PLAYBACK_H */
|