Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
layer3.c
Package: SHINE.rar [view]
Upload User: shenggui01
Upload Date: 2022-01-16
Package Size: 54k
Code Size: 4k
Category:
mpeg mp3
Development Platform:
C/C++
- /* layer3.c */
- #include "types.h"
- //#define NO_RESERVOIR
- int *scalefac_band_long;
- /* Scalefactor bands. */
- static int sfBandIndex[4][3][23] =
- {
- { /* MPEG-2.5 11.025 kHz */
- {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576},
- /* MPEG-2.5 12 kHz */
- {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576},
- /* MPEG-2.5 8 kHz */
- {0,12,24,36,48,60,72,88,108,132,160,192,232,280,336,400,476,566,568,570,572,574,576}
- },
- {
- {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
- },
- { /* Table B.2.b: 22.05 kHz */
- {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576},
- /* Table B.2.c: 24 kHz */
- {0,6,12,18,24,30,36,44,54,66,80,96,114,136,162,194,232,278,332,394,464,540,576},
- /* Table B.2.a: 16 kHz */
- {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576}
- },
- { /* Table B.8.b: 44.1 kHz */
- {0,4,8,12,16,20,24,30,36,44,52,62,74,90,110,134,162,196,238,288,342,418,576},
- /* Table B.8.c: 48 kHz */
- {0,4,8,12,16,20,24,30,36,42,50,60,72,88,106,128,156,190,230,276,330,384,576},
- /* Table B.8.a: 32 kHz */
- {0,4,8,12,16,20,24,30,36,44,54,66,82,102,126,156,194,240,296,364,448,550,576}
- }
- };
- /*
- * L3_compress:
- * ------------
- */
- void L3_compress(void)
- {
- long frames_processed;
- int ch;
- int i;
- int gr;
- unsigned long *buffer[2];
- long remainder;
- long bytes_per_frame;
- long lag;
- int mean_bits;
- int sideinfo_len;
- static int l3_enc[2][2][samp_per_frame2];
- static long l3_sb_sample[2][3][18][SBLIMIT];
- static long mdct_freq[2][2][samp_per_frame2];
- static L3_side_info_t side_info;
- if(config.mpeg.type == MPEG1)
- {
- config.mpeg.granules = 2;
- config.mpeg.samples_per_frame = samp_per_frame;
- config.mpeg.resv_limit = ((1<<9)-1)<<3;
- sideinfo_len = (config.mpeg.channels == 1) ? 168 : 288;
- }
- else /* mpeg 2/2.5 */
- {
- config.mpeg.granules = 1;
- config.mpeg.samples_per_frame = samp_per_frame2;
- config.mpeg.resv_limit = ((1<<8)-1)<<3;
- sideinfo_len = (config.mpeg.channels == 1) ? 104 : 168;
- }
- scalefac_band_long = sfBandIndex[config.mpeg.type][config.mpeg.samplerate_index];
- #ifdef NO_RESERVOIR
- config.mpeg.resv_limit = 0;
- #endif
- { /* find number of whole bytes per frame and the remainder */
- long x = config.mpeg.samples_per_frame * config.mpeg.bitr * (1000/8);
- bytes_per_frame = x / config.wave.samplerate;
- remainder = x % config.wave.samplerate;
- }
- config.mpeg.total_frames = /* round up */
- (config.wave.total_samples + config.mpeg.samples_per_frame - 1) /
- config.mpeg.samples_per_frame;
- printf("%ld framesn",config.mpeg.total_frames);
- frames_processed = lag = 0;
- open_bit_stream(config.outfile);
- while((buffer[0] = buffer[1] = wave_get()) != 0)
- {
- frames_processed++;
- if(((frames_processed & 7)==0) || (frames_processed >= config.mpeg.total_frames))
- printf("15[%ld] %ld%%", frames_processed,(frames_processed*100)/config.mpeg.total_frames);
- /* sort out padding */
- config.mpeg.padding = (lag += remainder) >= config.wave.samplerate;
- if (config.mpeg.padding)
- lag -= config.wave.samplerate;
- config.mpeg.bits_per_frame = 8*(bytes_per_frame + config.mpeg.padding);
- /* bits per channel per granule */
- mean_bits = (config.mpeg.bits_per_frame - sideinfo_len) >>
- (config.mpeg.granules + config.mpeg.channels - 2);
- /* polyphase filtering */
- for(gr=0; gr<config.mpeg.granules; gr++)
- for(ch=0; ch<config.mpeg.channels; ch++)
- for(i=0;i<18;i++)
- L3_window_filter_subband(&buffer[ch], &l3_sb_sample[ch][gr+1][i][0] ,ch);
- /* apply mdct to the polyphase output */
- L3_mdct_sub(l3_sb_sample, mdct_freq);
- /* bit and noise allocation */
- L3_iteration_loop(mdct_freq, &side_info, l3_enc, mean_bits);
- /* write the frame to the bitstream */
- L3_format_bitstream(l3_enc, &side_info);
- }
- close_bit_stream();
- }