![]() |
nochmal c++ nach delphi
hallo dp fans,
ich muss was für jemanden schreiben und auch etwas vorhandenes irgendwie in delphi umsetzen hier ist der code den ich in delphi irgendwie formulieren muss:
Delphi-Quellcode:
Hier die ac3.h die math.h ist ja bei c++ schon vorhanden
void imdct_do_256(double data[], double delay[]);
void imdct_do_512(double data[], double delay[]); typedef struct complex_s { double real; double imag; } complex_t; static uint_8 bit_reverse_512[128] = { 0x00, 0x40, 0x20, 0x60, 0x10, 0x50, 0x30, 0x70, 0x08, 0x48, 0x28, 0x68, 0x18, 0x58, 0x38, 0x78, 0x04, 0x44, 0x24, 0x64, 0x14, 0x54, 0x34, 0x74, 0x0c, 0x4c, 0x2c, 0x6c, 0x1c, 0x5c, 0x3c, 0x7c, 0x02, 0x42, 0x22, 0x62, 0x12, 0x52, 0x32, 0x72, 0x0a, 0x4a, 0x2a, 0x6a, 0x1a, 0x5a, 0x3a, 0x7a, 0x06, 0x46, 0x26, 0x66, 0x16, 0x56, 0x36, 0x76, 0x0e, 0x4e, 0x2e, 0x6e, 0x1e, 0x5e, 0x3e, 0x7e, 0x01, 0x41, 0x21, 0x61, 0x11, 0x51, 0x31, 0x71, 0x09, 0x49, 0x29, 0x69, 0x19, 0x59, 0x39, 0x79, 0x05, 0x45, 0x25, 0x65, 0x15, 0x55, 0x35, 0x75, 0x0d, 0x4d, 0x2d, 0x6d, 0x1d, 0x5d, 0x3d, 0x7d, 0x03, 0x43, 0x23, 0x63, 0x13, 0x53, 0x33, 0x73, 0x0b, 0x4b, 0x2b, 0x6b, 0x1b, 0x5b, 0x3b, 0x7b, 0x07, 0x47, 0x27, 0x67, 0x17, 0x57, 0x37, 0x77, 0x0f, 0x4f, 0x2f, 0x6f, 0x1f, 0x5f, 0x3f, 0x7f}; static uint_8 bit_reverse_256[64] = { 0x00, 0x20, 0x10, 0x30, 0x08, 0x28, 0x18, 0x38, 0x04, 0x24, 0x14, 0x34, 0x0c, 0x2c, 0x1c, 0x3c, 0x02, 0x22, 0x12, 0x32, 0x0a, 0x2a, 0x1a, 0x3a, 0x06, 0x26, 0x16, 0x36, 0x0e, 0x2e, 0x1e, 0x3e, 0x01, 0x21, 0x11, 0x31, 0x09, 0x29, 0x19, 0x39, 0x05, 0x25, 0x15, 0x35, 0x0d, 0x2d, 0x1d, 0x3d, 0x03, 0x23, 0x13, 0x33, 0x0b, 0x2b, 0x1b, 0x3b, 0x07, 0x27, 0x17, 0x37, 0x0f, 0x2f, 0x1f, 0x3f}; static complex_t buf[128]; /* Twiddle factor LUT */ static complex_t *w[7]; static complex_t w_1[1]; static complex_t w_2[2]; static complex_t w_4[4]; static complex_t w_8[8]; static complex_t w_16[16]; static complex_t w_32[32]; static complex_t w_64[64]; /* Twiddle factors for IMDCT */ static double xcos1[128]; static double xsin1[128]; static double xcos2[64]; static double xsin2[64]; /* Delay buffer for time domain interleaving */ static double delay[6][256]; /* Windowing function for Modified DCT */ static double window[] = { 0.00014, 0.00024, 0.00037, 0.00051, 0.00067, 0.00086, 0.00107, 0.00130, 0.00157, 0.00187, 0.00220, 0.00256, 0.00297, 0.00341, 0.00390, 0.00443, 0.00501, 0.00564, 0.00632, 0.00706, 0.00785, 0.00871, 0.00962, 0.01061, 0.01166, 0.01279, 0.01399, 0.01526, 0.01662, 0.01806, 0.01959, 0.02121, 0.02292, 0.02472, 0.02662, 0.02863, 0.03073, 0.03294, 0.03527, 0.03770, 0.04025, 0.04292, 0.04571, 0.04862, 0.05165, 0.05481, 0.05810, 0.06153, 0.06508, 0.06878, 0.07261, 0.07658, 0.08069, 0.08495, 0.08935, 0.09389, 0.09859, 0.10343, 0.10842, 0.11356, 0.11885, 0.12429, 0.12988, 0.13563, 0.14152, 0.14757, 0.15376, 0.16011, 0.16661, 0.17325, 0.18005, 0.18699, 0.19407, 0.20130, 0.20867, 0.21618, 0.22382, 0.23161, 0.23952, 0.24757, 0.25574, 0.26404, 0.27246, 0.28100, 0.28965, 0.29841, 0.30729, 0.31626, 0.32533, 0.33450, 0.34376, 0.35311, 0.36253, 0.37204, 0.38161, 0.39126, 0.40096, 0.41072, 0.42054, 0.43040, 0.44030, 0.45023, 0.46020, 0.47019, 0.48020, 0.49022, 0.50025, 0.51028, 0.52031, 0.53033, 0.54033, 0.55031, 0.56026, 0.57019, 0.58007, 0.58991, 0.59970, 0.60944, 0.61912, 0.62873, 0.63827, 0.64774, 0.65713, 0.66643, 0.67564, 0.68476, 0.69377, 0.70269, 0.71150, 0.72019, 0.72877, 0.73723, 0.74557, 0.75378, 0.76186, 0.76981, 0.77762, 0.78530, 0.79283, 0.80022, 0.80747, 0.81457, 0.82151, 0.82831, 0.83496, 0.84145, 0.84779, 0.85398, 0.86001, 0.86588, 0.87160, 0.87716, 0.88257, 0.88782, 0.89291, 0.89785, 0.90264, 0.90728, 0.91176, 0.91610, 0.92028, 0.92432, 0.92822, 0.93197, 0.93558, 0.93906, 0.94240, 0.94560, 0.94867, 0.95162, 0.95444, 0.95713, 0.95971, 0.96217, 0.96451, 0.96674, 0.96887, 0.97089, 0.97281, 0.97463, 0.97635, 0.97799, 0.97953, 0.98099, 0.98236, 0.98366, 0.98488, 0.98602, 0.98710, 0.98811, 0.98905, 0.98994, 0.99076, 0.99153, 0.99225, 0.99291, 0.99353, 0.99411, 0.99464, 0.99513, 0.99558, 0.99600, 0.99639, 0.99674, 0.99706, 0.99736, 0.99763, 0.99788, 0.99811, 0.99831, 0.99850, 0.99867, 0.99882, 0.99895, 0.99908, 0.99919, 0.99929, 0.99938, 0.99946, 0.99953, 0.99959, 0.99965, 0.99969, 0.99974, 0.99978, 0.99981, 0.99984, 0.99986, 0.99988, 0.99990, 0.99992, 0.99993, 0.99994, 0.99995, 0.99996, 0.99997, 0.99998, 0.99998, 0.99998, 0.99999, 0.99999, 0.99999, 0.99999, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000 }; static complex_t cmplx_mult(complex_t a, complex_t b) { complex_t ret; ret.real = a.real * b.real - a.imag * b.imag; ret.imag = a.real * b.imag + a.imag * b.real; return ret; } void imdct_init() { int i, k; complex_t angle_step; complex_t current_angle; /* Twiddle factors to turn IFFT into IMDCT */ for(i=0; i<128; i++) { xcos1[i] = cos(2.0 * M_PI * (8*i+1)/(8*N)); xsin1[i] = sin(2.0 * M_PI * (8*i+1)/(8*N)); } /* More twiddle factors to turn IFFT into IMDCT */ for(i=0; i<64; i++) { xcos2[i] = cos(2.0 * M_PI * (8*i+1)/(4*N)); xsin2[i] = sin(2.0 * M_PI * (8*i+1)/(4*N)); } /* Canonical twiddle factors for FFT */ w[0] = w_1; w[1] = w_2; w[2] = w_4; w[3] = w_8; w[4] = w_16; w[5] = w_32; w[6] = w_64; for( i = 0; i < 7; i++) { angle_step.real = cos(-2.0 * M_PI / (1 << (i+1))); angle_step.imag = sin(-2.0 * M_PI / (1 << (i+1))); current_angle.real = 1.0; current_angle.imag = 0.0; for (k = 0; k < 1 << i; k++) { w[i][k] = current_angle; current_angle = cmplx_mult(current_angle, angle_step); } } ZeroMemory(&delay, sizeof(delay)); } void imdct_do_512(double data[], double delay[]) { int i, k; int p, q; int m; int two_m; int two_m_plus_one; double tmp_a_i, tmp_a_r, tmp_b_i, tmp_b_r; double *data_ptr, *delay_ptr, *window_ptr; // Pre IFFT complex multiply plus IFFT cmplx conjugate and bit reverse permutation for(i=0; i < 128; i++) { k = bit_reverse_512[i]; /* z[i] = (X[256-2*i-1] + j * X[2*i]) * (xcos1[i] + j * xsin1[i]) ; */ buf[k].real = data[255 - (i<<1)] * xcos1[i] - data[i<<1] * xsin1[i]; buf[k].imag = - data[i<<1] * xcos1[i] - data[255 - (i<<1)] * xsin1[i]; } // FFT Merge for (m=0; m<7; m++) { if (m) two_m = 1<<m; else two_m = 1; two_m_plus_one = 1<<(m+1); for(k=0; k<two_m; k++) { for(i=0; i<128; i+=two_m_plus_one) { p = k + i; q = p + two_m; tmp_a_r = buf[p].real; tmp_a_i = buf[p].imag; tmp_b_r = buf[q].real * w[m][k].real - buf[q].imag * w[m][k].imag; tmp_b_i = buf[q].imag * w[m][k].real + buf[q].real * w[m][k].imag; buf[p].real = tmp_a_r + tmp_b_r; buf[p].imag = tmp_a_i + tmp_b_i; buf[q].real = tmp_a_r - tmp_b_r; buf[q].imag = tmp_a_i - tmp_b_i; } } } /* Post IFFT complex multiply plus IFFT complex conjugate*/ for(i=0; i<128; i++) { /* y[n] = z[n] * (xcos1[n] + j * xsin1[n]) ; */ tmp_a_r = buf[i].real; tmp_a_i = buf[i].imag; // Note that I flipped the signs on the imaginary ops to do the complex conj buf[i].real = tmp_a_r * xcos1[i] + tmp_a_i * xsin1[i]; buf[i].imag = tmp_a_r * xsin1[i] - tmp_a_i * xcos1[i]; } data_ptr = data; delay_ptr = delay; window_ptr = window; /* Window and convert to real valued signal */ for(i=0; i<64; i++) { *data_ptr++ = 2.0 * (-buf[64+i].imag * *window_ptr++ + *delay_ptr++); *data_ptr++ = 2.0 * ( buf[63-i].real * *window_ptr++ + *delay_ptr++); } for(i=0; i<64; i++) { *data_ptr++ = 2.0 * (-buf[i].real * *window_ptr++ + *delay_ptr++); *data_ptr++ = 2.0 * ( buf[127-i].imag * *window_ptr++ + *delay_ptr++); } /* The trailing edge of the window goes into the delay line */ delay_ptr = delay; for(i=0; i<64; i++) { *delay_ptr++ = -buf[64+i].real * *--window_ptr; // 64 - 127 *delay_ptr++ = buf[63-i].imag * *--window_ptr; // 63 - 0 } for(i=0; i<64; i++) { *delay_ptr++ = buf[i].imag * *--window_ptr; // 0 - 63 *delay_ptr++ = -buf[127-i].real * *--window_ptr; // 127 - 64 } } void imdct_do_256(double data[], double delay[]) { int i, k; int p, q; int m; int two_m; int two_m_plus_one; double tmp_a_i, tmp_a_r, tmp_b_i, tmp_b_r; double *data_ptr, *delay_ptr, *window_ptr; complex_t *buf_1, *buf_2; buf_1 = &buf[0]; buf_2 = &buf[64]; // Pre IFFT complex multiply plus IFFT cmplx conjugate and bit reverse // permutation for(i=0; i<64; i++) { /* X1[i] = X[2*i] */ /* X2[i] = X[2*i+1] */ k = bit_reverse_256[i]; p = (127 - (i<<1))<<1; q = i<<2; /* Z1[i] = (X1[128-2*i-1] + j * X1[2*i]) * (xcos2[i] + j * xsin2[i]); */ buf_1[k].real = data[p] * xcos2[i] - data[q] * xsin2[i]; buf_1[k].imag = - data[q] * xcos2[i] - data[p] * xsin2[i]; /* Z2[i] = (X2[128-2*i-1] + j * X2[2*i]) * (xcos2[i] + j * xsin2[i]); */ buf_2[k].real = data[p + 1] * xcos2[i] - data[q + 1] * xsin2[i]; buf_2[k].imag = - data[q + 1] * xcos2[i] - data[p + 1] * xsin2[i]; } // FFT Merge for (m=0; m<6; m++) { two_m = 1<<m; two_m_plus_one = 1<<(m+1); if(m) two_m = 1<<m; else two_m = 1; for(k=0; k<two_m; k++) { for(i=0; i<64; i+=two_m_plus_one) { p = k + i; q = p + two_m; // Do block 1 tmp_a_r = buf_1[p].real; tmp_a_i = buf_1[p].imag; tmp_b_r = buf_1[q].real * w[m][k].real - buf_1[q].imag * w[m][k].imag; tmp_b_i = buf_1[q].imag * w[m][k].real + buf_1[q].real * w[m][k].imag; buf_1[p].real = tmp_a_r + tmp_b_r; buf_1[p].imag = tmp_a_i + tmp_b_i; buf_1[q].real = tmp_a_r - tmp_b_r; buf_1[q].imag = tmp_a_i - tmp_b_i; //Do block 2 tmp_a_r = buf_2[p].real; tmp_a_i = buf_2[p].imag; tmp_b_r = buf_2[q].real * w[m][k].real - buf_2[q].imag * w[m][k].imag; tmp_b_i = buf_2[q].imag * w[m][k].real + buf_2[q].real * w[m][k].imag; buf_2[p].real = tmp_a_r + tmp_b_r; buf_2[p].imag = tmp_a_i + tmp_b_i; buf_2[q].real = tmp_a_r - tmp_b_r; buf_2[q].imag = tmp_a_i - tmp_b_i; } } } // Post IFFT complex multiply for(i=0; i<64; i++) { // Note that I flipped the signs on the imaginary ops to do the complex conj /* y1[n] = z1[n] * (xcos2[n] + j * xsin2[n]) ; */ tmp_a_r = buf_1[i].real; tmp_a_i = buf_1[i].imag; buf_1[i].real = tmp_a_r * xcos2[i] + tmp_a_i * xsin2[i]; buf_1[i].imag = tmp_a_r * xsin2[i] - tmp_a_i * xcos2[i]; /* y2[n] = z2[n] * (xcos2[n] + j * xsin2[n]) ; */ tmp_a_r = buf_2[i].real; tmp_a_i = buf_2[i].imag; buf_2[i].real = tmp_a_r * xcos2[i] + tmp_a_i * xsin2[i]; buf_2[i].imag = tmp_a_r * xsin2[i] - tmp_a_i * xcos2[i]; } data_ptr = data; delay_ptr = delay; window_ptr = window; /* Window and convert to real valued signal */ for(i=0; i<64; i++) { *data_ptr++ = 2.0 * (-buf_1[i].imag * *window_ptr++ + *delay_ptr++); *data_ptr++ = 2.0 * ( buf_1[63-i].real * *window_ptr++ + *delay_ptr++); } for(i=0; i<64; i++) { *data_ptr++ = 2.0 * (-buf_1[i].real * *window_ptr++ + *delay_ptr++); *data_ptr++ = 2.0 * ( buf_1[63-i].imag * *window_ptr++ + *delay_ptr++); } delay_ptr = delay; for(i=0; i<64; i++) { *delay_ptr++ = -buf_2[i].real * *--window_ptr; *delay_ptr++ = buf_2[63-i].imag * *--window_ptr; } for(i=0; i<64; i++) { *delay_ptr++ = buf_2[i].imag * *--window_ptr; *delay_ptr++ = -buf_2[63-i].real * *--window_ptr; } } void imdct(bsi_t *bsi, audblk_t *audblk, stream_samples_t samples) { int i; for(i=0; i<bsi->nfchans; i++) { if(audblk->blksw[i]) imdct_do_256(samples[i], delay[i]); else imdct_do_512(samples[i], delay[i]); } if (bsi->lfeon) imdct_do_512(samples[5], delay[5]); }
Delphi-Quellcode:
es ist sehr dringend ich bin jedoch leider damit etwas überfordert.
#include <windows.h>
typedef unsigned int uint_32; typedef unsigned short uint_16; typedef unsigned char uint_8; typedef signed int sint_32; typedef signed short sint_16; typedef signed char sint_8; uint_32 ac3_decode_data(uint_8 *data_start, uint_32 length, uint_32 start); /* Exponent strategy constants */ #define EXP_REUSE (0) #define EXP_D15 (1) #define EXP_D25 (2) #define EXP_D45 (3) /* Delta bit allocation constants */ #define DELTA_BIT_REUSE (0) #define DELTA_BIT_NEW (1) #define DELTA_BIT_NONE (2) #define DELTA_BIT_RESERVED (3) /* samples work structure */ typedef double stream_samples_t[6][256]; typedef struct syncinfo_s { /* Sync word == 0x0B77 */ uint_16 syncword; /* crc for the first 5/8 of the sync block */ /* uint_16 crc1; */ /* Stream Sampling Rate (kHz) 0 = 48, 1 = 44.1, 2 = 32, 3 = reserved */ uint_16 fscod; /* Frame size code */ uint_16 frmsizecod; /* Information not in the AC-3 bitstream, but derived */ /* Frame size in 16 bit words */ uint_16 frame_size; /* Bit rate in kilobits */ uint_16 bit_rate; /* sampling rate in hertz */ uint_32 sampling_rate; } syncinfo_t; typedef struct bsi_s { /* Bit stream identification == 0x8 */ uint_16 bsid; /* Bit stream mode */ uint_16 bsmod; /* Audio coding mode */ uint_16 acmod; /* If we're using the centre channel then */ /* centre mix level */ uint_16 cmixlev; /* If we're using the surround channel then */ /* surround mix level */ uint_16 surmixlev; /* If we're in 2/0 mode then */ /* Dolby surround mix level - NOT USED - */ uint_16 dsurmod; /* Low frequency effects on */ uint_16 lfeon; /* Dialogue Normalization level */ uint_16 dialnorm; /* Compression exists */ uint_16 compre; /* Compression level */ uint_16 compr; /* Language code exists */ uint_16 langcode; /* Language code */ uint_16 langcod; /* Audio production info exists*/ uint_16 audprodie; uint_16 mixlevel; uint_16 roomtyp; /* If we're in dual mono mode (acmod == 0) then extra stuff */ uint_16 dialnorm2; uint_16 compr2e; uint_16 compr2; uint_16 langcod2e; uint_16 langcod2; uint_16 audprodi2e; uint_16 mixlevel2; uint_16 roomtyp2; /* Copyright bit */ uint_16 copyrightb; /* Original bit */ uint_16 origbs; /* Timecode 1 exists */ uint_16 timecod1e; /* Timecode 1 */ uint_16 timecod1; /* Timecode 2 exists */ uint_16 timecod2e; /* Timecode 2 */ uint_16 timecod2; /* Additional bit stream info exists */ uint_16 addbsie; /* Additional bit stream length - 1 (in bytes) */ uint_16 addbsil; /* Additional bit stream information (max 64 bytes) */ uint_8 addbsi[64]; /* Information not in the AC-3 bitstream, but derived */ /* Number of channels (excluding LFE) * Derived from acmod */ uint_16 nfchans; } bsi_t; /* more pain */ typedef struct audblk_s { /* block switch bit indexed by channel num */ uint_16 blksw[5]; /* dither enable bit indexed by channel num */ uint_16 dithflag[5]; /* dynamic range gain exists */ uint_16 dynrnge; /* dynamic range gain */ uint_16 dynrng; /* if acmod==0 then */ /* dynamic range 2 gain exists */ uint_16 dynrng2e; /* dynamic range 2 gain */ uint_16 dynrng2; /* coupling strategy exists */ uint_16 cplstre; /* coupling in use */ uint_16 cplinu; /* channel coupled */ uint_16 chincpl[5]; /* if acmod==2 then */ /* Phase flags in use */ uint_16 phsflginu; /* coupling begin frequency code */ uint_16 cplbegf; /* coupling end frequency code */ uint_16 cplendf; /* coupling band structure bits */ uint_16 cplbndstrc[18]; /* Do coupling co-ords exist for this channel? */ uint_16 cplcoe[5]; /* Master coupling co-ordinate */ uint_16 mstrcplco[5]; /* Per coupling band coupling co-ordinates */ uint_16 cplcoexp[5][18]; uint_16 cplcomant[5][18]; /* Phase flags for dual mono */ uint_16 phsflg[18]; /* Is there a rematrixing strategy */ uint_16 rematstr; /* Rematrixing bits */ uint_16 rematflg[4]; /* Coupling exponent strategy */ uint_16 cplexpstr; /* Exponent strategy for full bandwidth channels */ uint_16 chexpstr[5]; /* Exponent strategy for lfe channel */ uint_16 lfeexpstr; /* Channel bandwidth for independent channels */ uint_16 chbwcod[5]; /* The absolute coupling exponent */ uint_16 cplabsexp; /* Coupling channel exponents (D15 mode gives 18 * 12 /3 encoded exponents */ uint_16 cplexps[18 * 12 / 3]; /* fbw channel exponents */ uint_16 exps[5][252 / 3]; /* channel gain range */ uint_16 gainrng[5]; /* low frequency exponents */ uint_16 lfeexps[3]; /* Bit allocation info */ uint_16 baie; /* Slow decay code */ uint_16 sdcycod; /* Fast decay code */ uint_16 fdcycod; /* Slow gain code */ uint_16 sgaincod; /* dB per bit code */ uint_16 dbpbcod; /* masking floor code */ uint_16 floorcod; /* SNR offset info */ uint_16 snroffste; /* coarse SNR offset */ uint_16 csnroffst; /* coupling fine SNR offset */ uint_16 cplfsnroffst; /* coupling fast gain code */ uint_16 cplfgaincod; /* fbw fine SNR offset */ uint_16 fsnroffst[5]; /* fbw fast gain code */ uint_16 fgaincod[5]; /* lfe fine SNR offset */ uint_16 lfefsnroffst; /* lfe fast gain code */ uint_16 lfefgaincod; /* Coupling leak info */ uint_16 cplleake; /* coupling fast leak initialization */ uint_16 cplfleak; /* coupling slow leak initialization */ uint_16 cplsleak; /* delta bit allocation info */ uint_16 deltbaie; /* coupling delta bit allocation exists */ uint_16 cpldeltbae; /* fbw delta bit allocation exists */ uint_16 deltbae[5]; /* number of cpl delta bit segments */ uint_16 cpldeltnseg; /* coupling delta bit allocation offset */ uint_16 cpldeltoffst[8]; /* coupling delta bit allocation length */ uint_16 cpldeltlen[8]; /* coupling delta bit allocation length */ uint_16 cpldeltba[8]; /* number of delta bit segments */ uint_16 deltnseg[5]; /* fbw delta bit allocation offset */ uint_16 deltoffst[5][8]; /* fbw delta bit allocation length */ uint_16 deltlen[5][8]; /* fbw delta bit allocation length */ uint_16 deltba[5][8]; /* skip length exists */ uint_16 skiple; /* skip length */ uint_16 skipl; //Removed Feb 2000 -ah /* channel mantissas */ //sint_16 chmant[5][256]; /* coupling mantissas */ sint_16 cplmant[256]; //Removed Feb 2000 -ah /* coupling mantissas */ //sint_16 lfemant[7]; /* Number of coupling sub-bands */ uint_16 ncplsubnd; /* Number of combined coupling sub-bands * Derived from ncplsubnd and cplbndstrc */ uint_16 ncplbnd; /* Number of exponent groups by channel * Derived from strmant, endmant */ uint_16 nchgrps[5]; /* Number of coupling exponent groups * Derived from cplbegf, cplendf, cplexpstr */ uint_16 ncplgrps; /* End mantissa numbers of fbw channels */ uint_16 endmant[5]; /* Start and end mantissa numbers for the coupling channel */ uint_16 cplstrtmant; uint_16 cplendmant; /* Decoded exponent info */ uint_16 fbw_exp[5][256]; uint_16 cpl_exp[256]; uint_16 lfe_exp[7]; /* Bit allocation pointer results */ uint_16 fbw_bap[5][256]; uint_16 cpl_bap[256]; uint_16 lfe_bap[7]; } audblk_t; /* coeff */ void mantissa_init(void); void coeff_unpack(bsi_t *bsi, audblk_t *audblk, stream_samples_t samples); /* crc */ int crc_process_frame(uint_8 *data,uint_32 num_bytes); /* downmix */ void drc_init(void); void downmix(audblk_t *audblk, bsi_t* bsi, stream_samples_t stream_samples, sint_16 *s16_samples); /* exponent */ #define UNPACK_FBW 1 #define UNPACK_CPL 2 #define UNPACK_LFE 4 void exponent_init(void); void exponent_unpack( bsi_t *bsi, audblk_t *audblk); /* imdct */ void imdct(bsi_t *bsi,audblk_t *audblk, stream_samples_t samples); void imdct_init(void); /* parse */ void parse_syncinfo(syncinfo_t *syncinfo,uint_8 *data); void parse_audblk(bsi_t *bsi,audblk_t *audblk); void parse_bsi(bsi_t *bsi); /* rematrix */ void rematrix(audblk_t *audblk, stream_samples_t samples); /* sanity check */ void sanity_check(bsi_t *bsi, audblk_t *audblk); void InitialAC3(void); unsigned char AC3Dec_Buffer[49152]; // 48KB/frame for 64~448 Kbps uint_32 error_flag; ich hoffe es gibt hier leute die mir helfen können danke schon im vorraus gruß sebby |
Re: nochmal c++ nach delphi
Das ist eine Menge Quellcode den Du da konvertiert haben willst.
Es wäre hilfreich, wenn Du schreibst, womit Du nicht zurecht kommst (der Rest ist stupide Tipparbeit). |
Re: nochmal c++ nach delphi
DAs hauptproblem dabei ist für mich dieser absatz:
Delphi-Quellcode:
da steht so viel drinnen da blick ich nicht so richtig durch
void imdct_init()
{ int i, k; complex_t angle_step; complex_t current_angle; /* Twiddle factors to turn IFFT into IMDCT */ for(i=0; i<128; i++) { xcos1[i] = cos(2.0 * M_PI * (8*i+1)/(8*N)); xsin1[i] = sin(2.0 * M_PI * (8*i+1)/(8*N)); } /* More twiddle factors to turn IFFT into IMDCT */ for(i=0; i<64; i++) { xcos2[i] = cos(2.0 * M_PI * (8*i+1)/(4*N)); xsin2[i] = sin(2.0 * M_PI * (8*i+1)/(4*N)); } /* Canonical twiddle factors for FFT */ w[0] = w_1; w[1] = w_2; w[2] = w_4; w[3] = w_8; w[4] = w_16; w[5] = w_32; w[6] = w_64; for( i = 0; i < 7; i++) { angle_step.real = cos(-2.0 * M_PI / (1 << (i+1))); angle_step.imag = sin(-2.0 * M_PI / (1 << (i+1))); current_angle.real = 1.0; current_angle.imag = 0.0; for (k = 0; k < 1 << i; k++) { w[i][k] = current_angle; current_angle = cmplx_mult(current_angle, angle_step); } } ZeroMemory(&delay, sizeof(delay)); } void imdct_do_512(double data[], double delay[]) { int i, k; int p, q; int m; int two_m; int two_m_plus_one; double tmp_a_i, tmp_a_r, tmp_b_i, tmp_b_r; double *data_ptr, *delay_ptr, *window_ptr; |
Re: nochmal c++ nach delphi
Zitat:
Delphi-Quellcode:
Der Rest ist selbsterklärend.
procedure imdct_init;
var i, k: Integer; angle_step: complex_t; current_angle: complex_t; begin (* Twiddle factors to turn IFFT into IMDCT *) for i := 0 to 127 do begin //... |
Re: nochmal c++ nach delphi
..und den selbserklärenden Rest zu bringen...
Delphi-Quellcode:
procedure imdct_init()
var i,k : Integer; angle_step, current_angle: complex_t; begin // Twiddle factors to turn IFFT into IMDCT */ for i:=0 to 127 do begin xcos1[i] := cos(2.0 * M_PI * (8*i+1)/(8*N)); xsin1[i] := sin(2.0 * M_PI * (8*i+1)/(8*N)); end; // More twiddle factors to turn IFFT into IMDCT */ for i:=0 to 63 do begin xcos2[i] := cos(2.0 * M_PI * (8*i+1)/(4*N)); xsin2[i] := sin(2.0 * M_PI * (8*i+1)/(4*N)); end; //* Canonical twiddle factors for FFT */ w[0] := w_1; w[1] := w_2; w[2] := w_4; w[3] := w_8; w[4] := w_16; w[5] := w_32; w[6] := w_64; for i:=0 to 6 do begin angle_step.real := cos(-2.0 * M_PI / (1 shl (i+1))); angle_step.imag := sin(-2.0 * M_PI / (1 shl (i+1))); current_angle.real := 1.0; current_angle.imag := 0.0; k:=0; while(k<(1 shl i))do begin w[i,k] := current_angle; current_angle := cmplx_mult(current_angle, angle_step); Inc(k); end; // for (k = 0; k < 1 << i; k++) // { // w[i][k] = current_angle; // current_angle = cmplx_mult(current_angle, angle_step); // } end; ZeroMemory(@delay, sizeof(delay)); end; procedure imdct_do_512(var data, delay:array of double); var i,k p,q, m, two_m, two_m_plus_one:Integer; tmp_a_i, tmp_a_r, tmp_b_i, tmp_b_r:double; data_ptr, delay_ptr, window_ptr : ^Double;; begin |
Re: nochmal c++ nach delphi
Danke für die antwort, aber ich hab noch ne stelle gefunden wo es sehr hakt nämlich diese hier:
Delphi-Quellcode:
ich komme mit dem vielen sinus und kosinus durcheinander und erkenne teilweise nicht so recht den sinn der formel
for(i=0; i<64; i++)
{ /* X1[i] = X[2*i] */ /* X2[i] = X[2*i+1] */ k = bit_reverse_256[i]; p = (127 - (i<<1))<<1; q = i<<2; /* Z1[i] = (X1[128-2*i-1] + j * X1[2*i]) * (xcos2[i] + j * xsin2[i]); */ buf_1[k].real = data[p] * xcos2[i] - data[q] * xsin2[i]; buf_1[k].imag = - data[q] * xcos2[i] - data[p] * xsin2[i]; /* Z2[i] = (X2[128-2*i-1] + j * X2[2*i]) * (xcos2[i] + j * xsin2[i]); */ buf_2[k].real = data[p + 1] * xcos2[i] - data[q + 1] * xsin2[i]; buf_2[k].imag = - data[q + 1] * xcos2[i] - data[p + 1] * xsin2[i]; } |
Re: nochmal c++ nach delphi
Delphi-Quellcode:
for i:=0 to 63 do
begin // /* X1[i] = X[2*i] */ // /* X2[i] = X[2*i+1] */ k := bit_reverse_256[i]; p := (127 - (i shl 1)) shl 1; q := i shl 2; // /* Z1[i] = (X1[128-2*i-1] + j * X1[2*i]) * (xcos2[i] + j * xsin2[i]); */ buf_1[k].real := data[p] * xcos2[i] - data[q] * xsin2[i]; buf_1[k].imag := - data[q] * xcos2[i] - data[p] * xsin2[i]; // /* Z2[i] = (X2[128-2*i-1] + j * X2[2*i]) * (xcos2[i] + j * xsin2[i]); */ buf_2[k].real := data[p + 1] * xcos2[i] - data[q + 1] * xsin2[i]; buf_2[k].imag := - data[q + 1] * xcos2[i] - data[p + 1] * xsin2[i]; end; |
Re: nochmal c++ nach delphi
DAnke für die schnelle Hilfe nun kann ich weitermachen
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 21:55 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz