⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 interface.c

📁 基于东南大学开发的SEP3203的ARM7中的所有驱动
💻 C
字号:
/*
 * $Id: interface.c,v 1.1.1.1 2004/12/22 10:02:27 zyu Exp $
 */

#include <stdio.h>
#include <string.h>

#include "mpg123.h"
#include "mpglib.h"


int InitMP3(struct mpstr *mp) 
{
	memset(mp,0,sizeof(struct mpstr));

	mp->framesize = 0;
	mp->frend = NULL;
	mp->fr.single = -1;
	mp->synth_bo = 1;

	main_dataend = main_databuf;
	
	init_layer3(SBLIMIT);

	return !0;
}

static void read_head(struct mpstr *mp, unsigned char *buf)
{
	unsigned long head;

	head = *buf++;
	head <<= 8;
	head |= *buf++;
	head <<= 8;
	head |= *buf++;
	head <<= 8;
	head |= *buf;

	mp->header = head;
}

int decodeMP3(struct mpstr *mp,char *in,int isize,char *out,
		int osize,int *pcmsize)
{
	unsigned char *buf = (unsigned char *)in;
	/* First decode header */
	if (isize < 4 || osize < 0)
		return 0;
/*
 * Modified by DSA 2003.11.04 ok
 */
	//read_head(mp, (unsigned char *)in);
	//unsigned char *buf = (unsigned char *)in;
	mp->header = *buf++;
	mp->header <<= 8;
	mp->header |= *buf++;
	mp->header <<= 8;
	mp->header |= *buf++;
	mp->header <<= 8;
	mp->header |= *buf;


	decode_header(&mp->fr,mp->header);
	if(mp->fr.framesize > isize)
		return 0;
	mp->framesize = mp->fr.framesize;
	
	mp->frend = (unsigned char *)in + mp->framesize;
	bufpointer = (unsigned char *)in + 4;
	bitindex = 0;
	*pcmsize = 0;
	if(mp->fr.error_protection)
           getbits(16);
     
    do_layer3(&mp->fr,(unsigned char *) out,pcmsize);
	return mp->framesize;
}

int set_pointer(long backstep)
{
	int main_datasize;
	 
	if (main_dataend - backstep < main_databuf) {
		fprintf(stderr,"Can't step back %ld!\n",backstep);
		return -1;
	}
	
	if (main_dataend > (main_databuf + 1024) && backstep) {
		memcpy(main_databuf, main_dataend - backstep, backstep);
		main_dataend = main_databuf + backstep;
	}
	main_datasize = gmp.frend - bufpointer;
	memcpy(main_dataend, bufpointer, main_datasize);
	bufpointer = main_dataend - backstep;
	main_dataend += main_datasize;
	bitindex = 0;
	return 0;
}

#ifdef	NEED_AIFF

#define IFF_ID_FORM 0x464f524d /* "FORM" */
#define IFF_ID_AIFF 0x41494646 /* "AIFF" */
#define IFF_ID_COMM 0x434f4d4d /* "COMM" */
#define IFF_ID_SSND 0x53534e44 /* "SSND" */
#define IFF_ID_MPEG 0x4d504547 /* "MPEG" */
#if 0
void
Write16BitsHighLow(unsigned char *buf, int i)
{
	*buf++ = (i>>8)&0xff;
	*buf++ = i&0xff;
}

void Write32BitsHighLow(unsigned char *buf, int i)
{
	Write16BitsHighLow(buf,(int)((i>>16)&0xffffL));
	Write16BitsHighLow(buf+2,(int)(i&0xffffL));
}
#endif

void WriteBytes(unsigned char *buf, unsigned char const *p, int n)
{
	while (n-- > 0)
		*buf++ = *p++;
}

#define kExtendedLength		10
static const unsigned char sfreq_ieeebits[8][kExtendedLength] = {
	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,},	// 0
	{0x40, 0x0c, 0xfa, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,},	// 16000
	{0x40, 0x0d, 0xac, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,},	// 22050
	{0x40, 0x0d, 0xbb, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,},	// 24000
	{0x40, 0x0d, 0xfa, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,},	// 32000
	{0x40, 0x0e, 0xac, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,},	// 44100
	{0x40, 0x0e, 0xbb, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,},	// 48000
	{0x7f, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, },	// infinite
};

/* only work for sampleRate */
void WriteIeeeExtendedHighLow(unsigned char *buf, int num)
{
	switch (num) {
	case 0:		WriteBytes(buf, sfreq_ieeebits[0], kExtendedLength); break;
	case 16000:	WriteBytes(buf, sfreq_ieeebits[1], kExtendedLength); break;
	case 22050:	WriteBytes(buf, sfreq_ieeebits[2], kExtendedLength); break;
	case 24000:	WriteBytes(buf, sfreq_ieeebits[3], kExtendedLength); break;
	case 32000:	WriteBytes(buf, sfreq_ieeebits[4], kExtendedLength); break;
	case 44100:	WriteBytes(buf, sfreq_ieeebits[5], kExtendedLength); break;
	case 48000:	WriteBytes(buf, sfreq_ieeebits[6], kExtendedLength); break;
	default:	WriteBytes(buf, sfreq_ieeebits[7], kExtendedLength); break;
	}
}

char *write_aiff(unsigned char *buf, struct frame *fr, int pcmsize)
{
    int stereo = fr->stereo;
    int sampleSize = 16;
    int sampleRate = freqs[fr->sampling_frequency];
    
    int chunkSize;
    int sampleBytes = (sampleSize / 8) + (sampleSize % 8 ? 1 : 0);
    
    /* write FORM chunk */
    chunkSize = 8 + 18 + 8 + stereo * pcmsize * sampleBytes;
    Write32BitsHighLow( buf, IFF_ID_FORM );
    Write32BitsHighLow( buf+4, chunkSize );
    Write32BitsHighLow( buf+8, IFF_ID_AIFF );
    /* write COMM chunk */
    Write32BitsHighLow( buf+12, IFF_ID_COMM );
    Write32BitsHighLow( buf+16, 18 ); /* chunk size */
    Write16BitsHighLow( buf+20, stereo );
    Write32BitsHighLow( buf+22, pcmsize );
    Write16BitsHighLow( buf+26, sampleSize );
    WriteIeeeExtendedHighLow( buf+28, sampleRate );
    /* write SSND chunk header */
    chunkSize = 8 + stereo * pcmsize * sampleBytes;
    Write32BitsHighLow( buf+28+kExtendedLength, IFF_ID_SSND );
    Write32BitsHighLow( buf+32+kExtendedLength, chunkSize );
    Write32BitsHighLow( buf+36+kExtendedLength, 0 ); /* offset */
    Write32BitsHighLow( buf+40+kExtendedLength, 0 ); /* block size */
    return 0;
}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -