//GiGaHeRz's SPU2 Driver //Copyright (c) 2003-2008, David Quintana // //This library is free software; you can redistribute it and/or //modify it under the terms of the GNU Lesser General Public //License as published by the Free Software Foundation; either //version 2.1 of the License, or (at your option) any later version. // //This library is distributed in the hope that it will be useful, //but WITHOUT ANY WARRANTY; without even the implied warranty of //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU //Lesser General Public License for more details. // //You should have received a copy of the GNU Lesser General Public //License along with this library; if not, write to the Free Software //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // #include "spu2.h" extern "C" { #include "liba52/inttypes.h" #include "liba52/a52.h" #include "liba52/mm_accel.h" } extern u32 spdif_read_data(u8 *buff, u32 max_data); #define DATA_SIZE 0x100000 u32 use51=0; u8 databuffer[DATA_SIZE]; u32 data_in_buffer; s32 output_buffer[0x10000][6]; s32 output_write_cursor=0; s32 output_read_cursor=0; s32 output_buffer_data=0; int flags,srate,bitrate; #define CHANNEL_CENTER 1 #define CHANNEL_STEREO 2 #define CHANNEL_SURROUND 4 #define CHANNEL_LFE 8 int sample_flags = 0; u32 frame_size; a52_state_t* ac3dec; sample_t *decode_buffer = NULL; s32 data_rate=4; int state=0; FILE *fSpdifDump; extern u32 core; void __fastcall ReadInput(V_Core& thiscore, s32& PDataL,s32& PDataR); union spdif_frame { // total size: 32bits struct { u32 preamble:4; //4 u32 databits:24; //28 u32 valid:1; //29 u32 subcode:1; //30 u32 chanstat:1; //31 u32 parity:1; //32 // parity not including preamble } bits; u32 whole; }; union spdif_block { spdif_frame frames[192]; u8 bytes [192*4]; }; /* spdif_block bbuffer[2]; u8 *bbuff = bbuffer[0].bytes; u32 bbuff_bytes = 0; */ bool check_frame(spdif_frame f) { u32 w = f.whole>>4; u32 t = 0; for(int i=0;i>28;i++) { t=t^(w&1); w>>=1; } return (t==0)&&(f.bits.valid); } void spdif_Write(s32 data) { spdif_frame f; f.whole=data; if(check_frame(f)) { int dec = f.bits.databits; databuffer[data_in_buffer++]=(dec )&0xFF; databuffer[data_in_buffer++]=(dec>> 8)&0xFF; databuffer[data_in_buffer++]=(dec>>16)&0xFF; } } void spdif_remove_data(unsigned int bytes) { if(bytes0)*-1; //1 if positive, -1 if negative, 0 otherwise n=abs(n)+1; //make it [1..2] s32 k=*(s32*)&n; k=k&0x7FFFFF; return k*sign; } void spdif_update() { s32 Data,Zero; core=0; V_Core& thiscore( Cores[core] ); for(int i=0;i