📄 mpegsound.h
字号:
#define FIXED_POINT/* MPEG/WAVE Sound library (C) 1997 by Woo-jae Jung */// Mpegsound.h// This is typeset for functions in MPEG/WAVE Sound library.// Now, it's for only linux-pc-?86/* Added for Pixil. This is stupid, so somebody fix it */#define HAVE_PTHREAD_H/************************************//* Include default library packages *//************************************/#include <stdio.h>#include <sys/types.h>#ifdef PTHREADEDMPEG#ifdef HAVE_PTHREAD_H#include <pthread.h>#else#ifdef HAVE_PTHREAD_MIT_PTHREAD_H#include <pthread/mit/pthread.h>#endif#endif#endif#ifndef _L__SOUND__#define _L__SOUND__/****************//* Sound Errors *//****************/// General error#define SOUND_ERROR_OK 0#define SOUND_ERROR_FINISH -1// Device error (for player)#define SOUND_ERROR_DEVOPENFAIL 1#define SOUND_ERROR_DEVBUSY 2#define SOUND_ERROR_DEVBADBUFFERSIZE 3#define SOUND_ERROR_DEVCTRLERROR 4// Sound file (for reader)#define SOUND_ERROR_FILEOPENFAIL 5#define SOUND_ERROR_FILEREADFAIL 6// Network#define SOUND_ERROR_UNKNOWNPROXY 7#define SOUND_ERROR_UNKNOWNHOST 8#define SOUND_ERROR_SOCKET 9#define SOUND_ERROR_CONNECT 10#define SOUND_ERROR_FDOPEN 11#define SOUND_ERROR_HTTPFAIL 12#define SOUND_ERROR_HTTPWRITEFAIL 13#define SOUND_ERROR_TOOMANYRELOC 14// Miscellneous (for translater)#define SOUND_ERROR_MEMORYNOTENOUGH 15#define SOUND_ERROR_EOF 16#define SOUND_ERROR_BAD 17#define SOUND_ERROR_THREADFAIL 18#define SOUND_ERROR_UNKNOWN 19/**************************//* Define values for MPEG *//**************************/#define SCALEBLOCK 12#define CALCBUFFERSIZE 512#define MAXSUBBAND 32#define MAXCHANNEL 2#define SCALE 32768#define MAXSCALE (SCALE-1)#define MINSCALE (-SCALE)#define RAWDATASIZE (2*2*32*SSLIMIT)#define LS 0#define RS 1#define SSLIMIT 18#define SBLIMIT 32#define WINDOWSIZE 4096// Huffmancode#define HTN 34/*******************************************//* Define values for Microsoft WAVE format *//*******************************************/#define RIFF 0x46464952#define WAVE 0x45564157#define FMT 0x20746D66#define DATA 0x61746164#define PCM_CODE 1#define WAVE_MONO 1#define WAVE_STEREO 2#define MODE_MONO 0#define MODE_STEREO 1/********************//* Type definitions *//********************/#ifndef FIXED_POINTtypedef float REAL;typedef float REAL13;typedef float REAL19;#else#include "fixed_point.h"#endiftypedef struct _waveheader{ u_int32_t main_chunk; // 'RIFF' u_int32_t length; // filelen u_int32_t chunk_type; // 'WAVE' u_int32_t sub_chunk; // 'fmt ' u_int32_t sc_len; // length of sub_chunk, =16 u_int16_t format; // should be 1 for PCM-code u_int16_t modus; // 1 Mono, 2 Stereo u_int32_t sample_fq; // frequence of sample u_int32_t byte_p_sec; u_int16_t byte_p_spl; // samplesize; 1 or 2 bytes u_int16_t bit_p_spl; // 8, 12 or 16 bit u_int32_t data_chunk; // 'data' u_int32_t data_length; // samplecount}WAVEHEADER;typedef struct{ bool generalflag; unsigned int part2_3_length; unsigned int big_values; unsigned int global_gain; unsigned int scalefac_compress; unsigned int window_switching_flag; unsigned int block_type; unsigned int mixed_block_flag; unsigned int table_select[3]; unsigned int subblock_gain[3]; unsigned int region0_count; unsigned int region1_count; unsigned int preflag; unsigned int scalefac_scale; unsigned int count1table_select;}layer3grinfo;typedef struct{ unsigned main_data_begin; unsigned private_bits; struct { unsigned scfsi[4]; layer3grinfo gr[2]; } ch[2];}layer3sideinfo;typedef struct{ int l[23]; /* [cb] */ int s[3][13]; /* [window][cb] */}layer3scalefactor; /* [ch] */typedef struct{ int tablename; unsigned int xlen, ylen; unsigned int linbits; unsigned int treelen; const unsigned int (*val)[2];}HUFFMANCODETABLE;/*********************************//* Sound input interface classes *//*********************************/// Superclass for Inputbitstream // Yet, Temporaryclass Soundinputstream{ public: Soundinputstream(); virtual ~ Soundinputstream(); static Soundinputstream *hopen(char *filename, int *errcode); int geterrorcode(void) { return __errorcode; }; virtual bool open(char *filename) = 0; virtual int getbytedirect(void) = 0; virtual bool _readbuffer(char *buffer, int size) = 0; virtual bool eof(void) = 0; virtual int getblock(char *buffer, int size) = 0; virtual int getsize(void) = 0; virtual int getposition(void) = 0; virtual void setposition(int pos) = 0; protected: void seterrorcode(int errorcode) { __errorcode = errorcode; }; private: int __errorcode;};// Inputstream from fileclass Soundinputstreamfromfile:public Soundinputstream{ public: Soundinputstreamfromfile() { fp = NULL; }; ~Soundinputstreamfromfile(); bool open(char *filename); bool _readbuffer(char *buffer, int bytes); int getbytedirect(void); bool eof(void); int getblock(char *buffer, int size); int getsize(void); int getposition(void); void setposition(int pos); private: FILE * fp; int size;};// Inputstream from httpclass Soundinputstreamfromhttp:public Soundinputstream{ public: Soundinputstreamfromhttp(); ~Soundinputstreamfromhttp(); bool open(char *filename); bool _readbuffer(char *buffer, int bytes); int getbytedirect(void); bool eof(void); int getblock(char *buffer, int size); int getsize(void); int getposition(void); void setposition(int pos); private: FILE * fp; int size; bool writestring(int fd, char *string); bool readstring(char *string, int maxlen, FILE * f); FILE *http_open(char *url);};/**********************************//* Sound player interface classes *//**********************************/// Superclass for playerclass Soundplayer{ public: Soundplayer() { __errorcode = SOUND_ERROR_OK; }; virtual ~ Soundplayer(); virtual bool initialize(char *filename) = 0; virtual void abort(void); virtual int getprocessed(void); virtual bool setsoundtype(int stereo, int samplesize, int speed) = 0; virtual bool resetsoundtype(void); virtual bool putblock(void *buffer, int size) = 0; virtual int getblocksize(void); int geterrorcode(void) { return __errorcode; }; protected: bool seterrorcode(int errorno) { __errorcode = errorno; return false; }; private: int __errorcode;};class Rawtofile:public Soundplayer{ public: ~Rawtofile(); bool initialize(char *filename); bool setsoundtype(int stereo, int samplesize, int speed); bool putblock(void *buffer, int size); private: int filehandle; int rawstereo, rawsamplesize, rawspeed;};// Class for playing raw dataclass Rawplayer:public Soundplayer{ public: ~Rawplayer(); bool initialize(char *filename); void abort(void); int getprocessed(void); bool setsoundtype(int stereo, int samplesize, int speed); bool resetsoundtype(void); bool putblock(void *buffer, int size); int getblocksize(void); void setquota(int q) { quota = q; }; int getquota(void) { return quota; }; static char *defaultdevice; static int setvolume(int volume); private: short int rawbuffer[RAWDATASIZE]; int rawbuffersize; int audiohandle, audiobuffersize; int rawstereo, rawsamplesize, rawspeed; bool forcetomono, forceto8; int quota;};/*********************************//* Data format converter classes *//*********************************/// Class for converting wave format to raw formatclass Wavetoraw{ public: Wavetoraw(Soundinputstream * loader, Soundplayer * player); ~Wavetoraw(); bool initialize(void); void setforcetomono(bool flag) { forcetomonoflag = flag; }; bool run(void); int getfrequency(void) const { return speed; }; bool isstereo(void) const { return stereo; }; int getsamplesize(void) const { return samplesize; }; int geterrorcode(void) const { return __errorcode; }; int gettotallength(void) const { return size / pcmsize; }; int getcurrentpoint(void) const { return currentpoint / pcmsize; }; void setcurrentpoint(int p); private: int __errorcode; void seterrorcode(int errorcode) { __errorcode = errorcode; }; bool forcetomonoflag; Soundinputstream *loader; Soundplayer *player; bool initialized; char *buffer; int buffersize; int samplesize, speed, stereo; int currentpoint, size; int pcmsize; bool testwave(char *buffer);};// Class for Mpeg layer3class Mpegbitwindow{ public: Mpegbitwindow() { bitindex = point = 0; }; void initialize(void) { bitindex = point = 0; }; int gettotalbit(void) const { return bitindex;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -