From 488813197292bd1db8d533d7b42c38852971c2e8 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Sat, 22 Jun 2013 16:41:16 -0400 Subject: Update software recording engine to latest codec interface. Basically, just give it a good rewrite. Software codec recording can be implemented in a more straightforward and simple manner and made more robust through the better codec control now available. Encoded audio buffer uses a packed format instead of fixed-size chunks and uses smaller data headers leading to more efficient usage. The greatest benefit is with a VBR format like wavpack which needs to request a maximum size but only actually ends up committing part of that request. No guard buffers are used for either PCM or encoded audio. PCM is read into the codec's provided buffer and mono conversion done at that time in the core if required. Any highly-specialized sample conversion is still done within the codec itself, such as 32-bit (wavpack) or interleaved mono (mp3). There is no longer a separate filename array. All metadata goes onto the main encoded audio buffer, eliminating any predermined file limit on the buffer as well as not wasting the space for unused path queue slots. The core and codec interface is less awkward and a bit more sensible. Some less useful interface features were removed. Threads are kept on narrow code paths ie. the audio thread never calls encoding functions and the codec thread never calls file functions as before. Codecs no longer call file functions directly. Writes are buffered in the core and data written to storage in larger chunks to speed up flushing of data. In fact, codecs are no longer aware of the stream being a file at all and have no access to the fd. SPDIF frequency detection no longer requires a restart of recording or plugging the source before entering the screen. It will poll for changes and update when stopped or prerecording (which does discard now-invalid prerecorded data). I've seen to it that writing a proper header on full disk works when the format makes it reasonably practical to do so. Other cases may have incorrect data sizes but sample info will be in tact. File left that way may play anyway. mp3_enc.codec acquires the ability to write 'Info' headers with LAME tags to make it gapless (bonus). Change-Id: I670685166d5eb32ef58ef317f50b8af766ceb653 Reviewed-on: http://gerrit.rockbox.org/493 Reviewed-by: Michael Sevakis Tested-by: Michael Sevakis --- apps/recorder/pcm_record.h | 74 ++++++++++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 28 deletions(-) (limited to 'apps/recorder/pcm_record.h') diff --git a/apps/recorder/pcm_record.h b/apps/recorder/pcm_record.h index bff7881605..cf7197946a 100644 --- a/apps/recorder/pcm_record.h +++ b/apps/recorder/pcm_record.h @@ -8,6 +8,7 @@ * $Id$ * * Copyright (C) 2005 by Linus Nielsen Feltzing + * Copyright (C) 2006-2013 by Michael Sevakis * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -18,47 +19,64 @@ * KIND, either express or implied. * ****************************************************************************/ - #ifndef PCM_RECORD_H #define PCM_RECORD_H -#include "config.h" +/** Warnings (recording may continue with possible data loss) + ** Reset of recording clears, otherwise see notes below + */ -/** Warnings **/ -/* pcm (dma) buffer has overflowed */ +/* PCM buffer has overflowed; PCM samples were dropped */ +/* persists until: stop, new file, clear */ #define PCMREC_W_PCM_BUFFER_OVF 0x00000001 -/* encoder output buffer has overflowed */ +/* encoder output buffer has overflowed; encoded data was dropped */ +/* persists until: stop, new file, clear */ #define PCMREC_W_ENC_BUFFER_OVF 0x00000002 -/** Errors **/ +/* encoder and set/detected sample rates do not match */ +/* persists until: rates match, clear */ +#define PCMREC_W_SAMPR_MISMATCH 0x00000004 +/* PCM frame skipped because of recoverable DMA error */ +/* persists until: clear */ +#define PCMREC_W_DMA 0x00000008 +/* internal file size limit was reached; encoded data was dropped */ +/* persists until: stop, new file, clear */ +#define PCMREC_W_FILE_SIZE 0x00000010 + +/* all warning flags */ +#define PCMREC_W_ALL 0x0000001f + +/** Errors (recording should be reset) + ** + ** Stopping recording if recording clears internally and externally visible + ** status must be cleared with audio_error_clear() + ** reset of recording clears + */ + +/* DMA callback has reported an error */ +#define PCMREC_E_DMA 0x80010000 /* failed to load encoder */ -#define PCMREC_E_LOAD_ENCODER 0x80001000 +#define PCMREC_E_LOAD_ENCODER 0x80020000 /* error originating in encoder */ -#define PCMREC_E_ENCODER 0x80002000 -/* filename queue has desynced from stream markers */ -#define PCMREC_E_FNQ_DESYNC 0x80004000 +#define PCMREC_E_ENCODER 0x80040000 +/* error from encoder setup of stream parameters */ +#define PCMREC_E_ENC_SETUP 0x80080000 +/* error writing to output stream */ +#define PCMREC_E_ENCODER_STREAM 0x80100000 /* I/O error has occurred */ -#define PCMREC_E_IO 0x80008000 -#ifdef DEBUG -/* encoder has written past end of allocated space */ -#define PCMREC_E_CHUNK_OVF 0x80010000 -#endif /* DEBUG */ -/* DMA callback has reported an error */ -#define PCMREC_E_DMA 0x80020000 +#define PCMREC_E_IO 0x80200000 -/** General functions for high level codec recording **/ -/* pcm_rec_error_clear is deprecated for general use. audio_error_clear - should be used */ +/* all error flags */ +#define PCMREC_E_ALL 0x803f0000 + +/* Functions called by audio_thread.c */ void pcm_rec_error_clear(void); -/* pcm_rec_status is deprecated for general use. audio_status merges the - results for consistency with the hardware codec version */ unsigned int pcm_rec_status(void); -unsigned long pcm_rec_get_warnings(void); -void pcm_rec_init(void) INIT_ATTR; -int pcm_rec_current_bitrate(void); -int pcm_rec_encoder_afmt(void); /* AFMT_* value, AFMT_UNKNOWN if none */ -int pcm_rec_rec_format(void); /* Format index or -1 otherwise */ +uint32_t pcm_rec_get_warnings(void); +#ifdef HAVE_SPDIF_IN unsigned long pcm_rec_sample_rate(void); -int pcm_get_num_unprocessed(void); +#endif + +void recording_init(void); /* audio.h contains audio_* recording functions */ -- cgit v1.2.3