nkeynes@644: /* nkeynes@644: * This file has been modified for the cdrkit suite. nkeynes@644: * nkeynes@644: * The behaviour and appearence of the program code below can differ to a major nkeynes@644: * extent from the version distributed by the original author(s). nkeynes@644: * nkeynes@644: * For details, see Changelog file distributed with the cdrkit package. If you nkeynes@644: * received this file from another source then ask the distributing person for nkeynes@644: * a log of modifications. nkeynes@644: * nkeynes@644: */ nkeynes@644: nkeynes@644: /* @(#)ecc.h 1.4 02/10/19 Copyright 1998-2002 Heiko Eissfeldt, Joerg Schilling */ nkeynes@644: nkeynes@644: /* nkeynes@644: * compact disc reed-solomon routines nkeynes@644: * nkeynes@644: * (c) 1998-2002 by Heiko Eissfeldt, heiko@colossus.escape.de nkeynes@644: * (c) 2002 by Joerg Schilling nkeynes@644: */ nkeynes@644: /* nkeynes@644: * This program is free software; you can redistribute it and/or modify nkeynes@644: * it under the terms of the GNU General Public License version 2 nkeynes@644: * as published by the Free Software Foundation. nkeynes@644: * nkeynes@644: * This program is distributed in the hope that it will be useful, nkeynes@644: * but WITHOUT ANY WARRANTY; without even the implied warranty of nkeynes@644: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the nkeynes@644: * GNU General Public License for more details. nkeynes@644: * nkeynes@644: * You should have received a copy of the GNU General Public License along with nkeynes@644: * this program; see the file COPYING. If not, write to the Free Software nkeynes@644: * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. nkeynes@644: */ nkeynes@644: nkeynes@644: #define RS_L12_BITS 8 nkeynes@644: nkeynes@644: /* audio sector definitions for CIRC */ nkeynes@644: #define FRAMES_PER_SECTOR 98 nkeynes@644: /* user data bytes per frame */ nkeynes@644: #define L1_RAW 24 nkeynes@644: /* parity bytes with 8 bit */ nkeynes@644: #define L1_Q 4 nkeynes@644: #define L1_P 4 nkeynes@644: nkeynes@644: int cd_build_address(unsigned char inout[], int sectortype, unsigned address); nkeynes@644: nkeynes@644: /* audio sector Cross Interleaved Reed-Solomon Code (CIRC) encoder (layer 1) */ nkeynes@644: /* adds P- and Q- parity information to audio (f2) frames. Also nkeynes@644: optionally handles the various delays and permutations. The output with all nkeynes@644: stages enabled can be fed into the Eight-Fourteen-Modulator. nkeynes@644: On input: 2352 bytes of audio data is given. nkeynes@644: On output: 3136 bytes of CIRC enriched audio data are returned. nkeynes@644: */ nkeynes@644: int do_encode_L1(unsigned char in[L1_RAW*FRAMES_PER_SECTOR], nkeynes@644: unsigned char out[(L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR], nkeynes@644: int delay1, int delay2, int delay3, int scramble); nkeynes@644: nkeynes@644: /* data sector definitions for RSPC */ nkeynes@644: /* user data bytes per frame */ nkeynes@644: #define L2_RAW (1024*2) nkeynes@644: /* parity bytes for 16 bit units */ nkeynes@644: #define L2_Q (26*2*2) nkeynes@644: #define L2_P (43*2*2) nkeynes@644: nkeynes@644: /* known sector types */ nkeynes@644: #define MODE_0 GDROM_MODE0 nkeynes@644: #define MODE_1 GDROM_MODE1 nkeynes@644: #define MODE_2 GDROM_MODE2_FORMLESS nkeynes@644: #define MODE_2_FORM_1 GDROM_MODE2_FORM1 nkeynes@644: #define MODE_2_FORM_2 GDROM_MODE2_FORM2 nkeynes@644: nkeynes@644: /* set one of the MODE_* constants for subsequent data sector formatting */ nkeynes@644: int set_sector_type(int st); nkeynes@644: /* get the current sector type setting for data sector formatting */ nkeynes@644: int get_sector_type(void); nkeynes@644: nkeynes@644: /* data sector layer 2 Reed-Solomon Product Code encoder */ nkeynes@644: /* encode the given data portion depending on sector type (see nkeynes@644: get/set_sector_type() functions). Use the given address for the header. nkeynes@644: The returned data is __unscrambled__ and not in F2-frame format (for that nkeynes@644: see function scramble_L2()). nkeynes@644: Supported sector types: nkeynes@644: MODE_0: a 12-byte sync field, a header and 2336 zeros are returned. nkeynes@644: MODE_1: the user data portion (2048 bytes) has to be given nkeynes@644: at offset 16 in the inout array. nkeynes@644: Sync-, header-, edc-, spare-, p- and q- fields will be added. nkeynes@644: MODE_2: the user data portion (2336 bytes) has to be given nkeynes@644: at offset 16 in the inout array. nkeynes@644: Sync- and header- fields will be added. nkeynes@644: MODE_2_FORM_1: the user data portion (8 bytes subheader followed nkeynes@644: by 2048 bytes data) has to be given at offset 16 nkeynes@644: in the inout array. nkeynes@644: Sync-, header-, edc-, p- and q- fields will be added. nkeynes@644: MODE_2_FORM_2: the user data portion (8 bytes subheader followed nkeynes@644: by 2324 bytes data) has to be given at offset 16 nkeynes@644: in the inout array. nkeynes@644: Sync-, header- and edc- fields will be added. nkeynes@644: */ nkeynes@644: int do_encode_L2(unsigned char *inout, int sectortype, unsigned address); nkeynes@644: int decode_L2_Q(unsigned char inout[4 + L2_RAW + 12 + L2_Q]); nkeynes@644: int decode_L2_P(unsigned char inout[4 + L2_RAW + 12 + L2_Q + L2_P]); nkeynes@644: unsigned int build_edc(unsigned char inout[], int from, int upto); nkeynes@644: nkeynes@644: /* generates f2 frames from otherwise fully formatted sectors (generated by nkeynes@644: do_encode_L2()). */ nkeynes@644: #define EDC_SCRAMBLE_NOSWAP 1 /* Do not swap bytes while scrambling */ nkeynes@644: int scramble_L2(unsigned char *inout); nkeynes@644: nkeynes@644: /* r-w sub channel definitions */ nkeynes@644: #define RS_SUB_RW_BITS 6 nkeynes@644: nkeynes@644: #define PACKETS_PER_SUBCHANNELFRAME 4 nkeynes@644: #define LSUB_RAW 18 nkeynes@644: #define LSUB_QRAW 2 nkeynes@644: /* 6 bit */ nkeynes@644: #define LSUB_Q 2 nkeynes@644: #define LSUB_P 4 nkeynes@644: nkeynes@644: /* R-W subchannel encoder */ nkeynes@644: /* On input: 72 bytes packed user data, four frames with each 18 bytes. nkeynes@644: On output: per frame: 2 bytes user data, 2 bytes Q parity, nkeynes@644: 16 bytes user data, 4 bytes P parity. nkeynes@644: Options: nkeynes@644: delay1: use low level delay line nkeynes@644: scramble: perform low level permutations nkeynes@644: */ nkeynes@644: int do_encode_sub(unsigned char in[LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME], nkeynes@644: unsigned char out[(LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME], nkeynes@644: int delay1, int scramble); nkeynes@644: int do_decode_sub(unsigned char in[(LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME], nkeynes@644: unsigned char out[LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME], nkeynes@644: int delay1, int scramble); nkeynes@644: nkeynes@644: int decode_LSUB_Q(unsigned char inout[LSUB_QRAW + LSUB_Q]); nkeynes@644: int decode_LSUB_P(unsigned char inout[LSUB_RAW + LSUB_Q + LSUB_P]);