#ifndef WRAPPER_H #define WRAPPER_H #include #include #include "mad.h" #include "decoder.h" using namespace emscripten; class MadHeader : public mad_header { public: mad_layer getLayer() const {return layer;} void setLayer(mad_layer lay) {layer = lay;} int getMode_extension() const {return mode_extension;} void setMode_extension(int ext) {mode_extension = ext;} mad_mode getMode() const {return mode;} void setMode(mad_mode value) {mode = value;} mad_emphasis getEmphasis() const {return emphasis;} void setEmphasis(mad_emphasis value) {emphasis = value;} long unsigned int getBitrate() const {return bitrate;} void setBitrate(long unsigned int value) {bitrate = value;} unsigned int getSamplerate() const {return samplerate;} void setSamplerate(unsigned int value) {samplerate = value;} short unsigned int getCrc_check() const {return crc_check;} void setCrc_check(short unsigned int value) {crc_check = value;} short unsigned int getCrc_target() const {return crc_target;} void setCrc_target(unsigned long int value) {crc_target = value;} int getFlags() const {return flags;} void setFlags(int ext) {flags = ext;} int getPrivate_bits() const {return private_bits;} void setPrivate_bits(int ext) {private_bits = ext;} mad_timer_t getDuration() const {return duration;} void setDuration(mad_timer_t ext) {duration = ext;} }; MadHeader* mad_header_create(); class MadFrame : public mad_frame { public: int getOptions() const {return options;} void setOptions(int lay) {options = lay;} val getSbsample() const; val getOverlap() const; int decode(mad_stream* stream); const MadHeader* header() const {return static_cast(&(mad_frame::header));} }; MadFrame* mad_frame_create(); class MadStream : public mad_stream { //unsigned char const *buffer; /* input bitstream buffer */ //unsigned char const *bufend; /* end of buffer */ //unsigned long skiplen; /* bytes to skip before next frame */ //unsigned char const *this_frame; /* start of current frame */ //unsigned char const *next_frame; /* start of next frame */ //struct mad_bitptr ptr; /* current processing bit pointer */ //struct mad_bitptr anc_ptr; /* ancillary bits pointer */ //unsigned int anc_bitlen; /* number of ancillary bits */ public: int getSync() const {return sync;} void setSync(int value) {sync = value;} unsigned long getFreeRate() const {return freerate;} void setFreeRate(unsigned long value) {freerate = value;} int getOptions() const {return options;} void setOptions(int value) {options = value;} mad_error getError() const {return error;} void setError(mad_error value) {error = value;} val mainData(); unsigned int getMdLen() const {return md_len;} void setMdLen(unsigned int value) {md_len = value;} void setBuffer(intptr_t bufferPtr, unsigned long length); }; MadStream* mad_stream_create(); class MadPCM : public mad_pcm { public: unsigned int getSamplerate() const {return samplerate;} void setSamplerate(unsigned int value) {samplerate = value;} unsigned short getChannels() const {return channels;} void setChannels(unsigned short value) {channels = value;} unsigned short getLength() const {return length;} void setLength(unsigned short value) {length = value;} val samples() const; }; MadPCM* mad_pcm_create(); class MadSynth : public mad_synth { public: unsigned int getPhase() const {return phase;} void setPhase(unsigned int value) {phase = value;} const MadPCM* pcm() const {return static_cast(&(mad_synth::pcm));} void frame(mad_frame const * frame); }; MadSynth* mad_synth_create(); EMSCRIPTEN_BINDINGS(jsmad) { enum_("mad_layer") .value("MAD_LAYER_I", MAD_LAYER_I) .value("MAD_LAYER_II", MAD_LAYER_II) .value("MAD_LAYER_III", MAD_LAYER_III); enum_("mad_mode") .value("MAD_MODE_DUAL_CHANNEL", MAD_MODE_DUAL_CHANNEL) .value("MAD_MODE_JOINT_STEREO", MAD_MODE_JOINT_STEREO) .value("MAD_MODE_SINGLE_CHANNEL", MAD_MODE_SINGLE_CHANNEL) .value("MAD_MODE_STEREO", MAD_MODE_STEREO); enum_("mad_emphasis") .value("MAD_EMPHASIS_50_15_US", MAD_EMPHASIS_50_15_US) .value("MAD_EMPHASIS_CCITT_J_17", MAD_EMPHASIS_CCITT_J_17) .value("MAD_EMPHASIS_NONE", MAD_EMPHASIS_NONE) .value("MAD_EMPHASIS_RESERVED", MAD_EMPHASIS_RESERVED); enum_("mad_error") .value("MAD_ERROR_NONE", MAD_ERROR_NONE) /* no error */ .value("MAD_ERROR_BUFLEN", MAD_ERROR_BUFLEN) /* input buffer too small (or EOF) */ .value("MAD_ERROR_BUFPTR", MAD_ERROR_BUFPTR) /* invalid (null) buffer pointer */ .value("MAD_ERROR_NOMEM", MAD_ERROR_NOMEM) /* not enough memory */ .value("MAD_ERROR_LOSTSYNC", MAD_ERROR_LOSTSYNC) /* lost synchronization */ .value("MAD_ERROR_BADLAYER", MAD_ERROR_BADLAYER) /* reserved header layer value */ .value("MAD_ERROR_BADBITRATE", MAD_ERROR_BADBITRATE) /* forbidden bitrate value */ .value("MAD_ERROR_BADSAMPLERATE", MAD_ERROR_BADSAMPLERATE) /* reserved sample frequency value */ .value("MAD_ERROR_BADEMPHASIS", MAD_ERROR_BADEMPHASIS) /* reserved emphasis value */ .value("MAD_ERROR_BADCRC", MAD_ERROR_BADCRC) /* CRC check failed */ .value("MAD_ERROR_BADBITALLOC", MAD_ERROR_BADBITALLOC) /* forbidden bit allocation value */ .value("MAD_ERROR_BADSCALEFACTOR", MAD_ERROR_BADSCALEFACTOR)/* bad scalefactor index */ .value("MAD_ERROR_BADMODE", MAD_ERROR_BADMODE) /* bad bitrate/mode combination */ .value("MAD_ERROR_BADFRAMELEN", MAD_ERROR_BADFRAMELEN) /* bad frame length */ .value("MAD_ERROR_BADBIGVALUES", MAD_ERROR_BADBIGVALUES) /* bad big_values count */ .value("MAD_ERROR_BADBLOCKTYPE", MAD_ERROR_BADBLOCKTYPE) /* reserved block_type */ .value("MAD_ERROR_BADSCFSI", MAD_ERROR_BADSCFSI) /* bad scalefactor selection info */ .value("MAD_ERROR_BADDATAPTR", MAD_ERROR_BADDATAPTR) /* bad main_data_begin pointer */ .value("MAD_ERROR_BADPART3LEN", MAD_ERROR_BADPART3LEN) /* bad audio data length */ .value("MAD_ERROR_BADHUFFTABLE", MAD_ERROR_BADHUFFTABLE) /* bad Huffman table select */ .value("MAD_ERROR_BADHUFFDATA", MAD_ERROR_BADHUFFDATA) /* Huffman data overrun */ .value("MAD_ERROR_BADSTEREO", MAD_ERROR_BADSTEREO); /* incompatible block_type for JS */ class_("mad_header"); class_>("MadHeader") .constructor(&mad_header_create, allow_raw_pointers()) .property("layer", &MadHeader::getLayer, &MadHeader::setLayer) .property("mode_extension", &MadHeader::getMode_extension, &MadHeader::setMode_extension) .property("mode", &MadHeader::getMode, &MadHeader::setMode) .property("emphasis", &MadHeader::getEmphasis, &MadHeader::setEmphasis) .property("bitrate", &MadHeader::getBitrate, &MadHeader::setBitrate) .property("samplerate", &MadHeader::getSamplerate, &MadHeader::setSamplerate) .property("crc_check", &MadHeader::getCrc_check, &MadHeader::setCrc_check) .property("crc_target", &MadHeader::getCrc_target, &MadHeader::setCrc_target) .property("flags", &MadHeader::getFlags, &MadHeader::setFlags) .property("private_bits", &MadHeader::getPrivate_bits, &MadHeader::setPrivate_bits) .property("duration", &MadHeader::getDuration, &MadHeader::setDuration); function("mad_header_init", &mad_header_init, allow_raw_pointers()); class_("mad_frame"); class_>("MadFrame") .constructor(&mad_frame_create, allow_raw_pointers()) .property("options", &MadFrame::getOptions, &MadFrame::setOptions) .function("header", &MadFrame::header, allow_raw_pointers()) .function("sbsample", &MadFrame::getSbsample) .function("overlap", &MadFrame::getOverlap) .function("decode", &MadFrame::decode, allow_raw_pointers()); value_object("mad_timer_t") .field("seconds", &mad_timer_t::seconds) .field("fraction", &mad_timer_t::fraction); function("mad_frame_init", &mad_frame_init, allow_raw_pointers()); function("mad_frame_finish", &mad_frame_finish, allow_raw_pointers()); class_("mad_bitptr"); class_("mad_stream"); class_>("MadStream") .constructor(&mad_stream_create, allow_raw_pointers()) .property("sync", &MadStream::getSync, &MadStream::setSync) .property("freerate", &MadStream::getFreeRate, &MadStream::setFreeRate) .property("options", &MadStream::getOptions, &MadStream::setOptions) .property("error", &MadStream::getError, &MadStream::setError) .property("mdLen", &MadStream::getMdLen, &MadStream::setMdLen) .function("mainData", &MadStream::mainData) .function("setBuffer", &MadStream::setBuffer, allow_raw_pointers()); function("mad_stream_init", &mad_stream_init, allow_raw_pointers()); function("mad_stream_finish", &mad_stream_finish, allow_raw_pointers()); function("mad_stream_buffer", &mad_stream_buffer, allow_raw_pointers()); function("mad_stream_sync", &mad_stream_sync, allow_raw_pointers()); class_("mad_pcm"); class_>("MadPCM") .constructor(&mad_pcm_create, allow_raw_pointers()) .property("samplerate", &MadPCM::getSamplerate, &MadPCM::setSamplerate) .property("channels", &MadPCM::getChannels, &MadPCM::setChannels) .property("length", &MadPCM::getLength, &MadPCM::setLength) .function("samples", &MadPCM::samples, allow_raw_pointers()); function("mad_synth_init", &mad_synth_init, allow_raw_pointers()); function("mad_synth_frame", &mad_synth_frame, allow_raw_pointers()); class_("mad_synth"); class_>("MadSynth") .constructor(&mad_synth_create, allow_raw_pointers()) .property("phase", &MadSynth::getPhase, &MadSynth::setPhase) .function("pcm", &MadSynth::pcm, allow_raw_pointers()) .function("frame", &MadSynth::frame, allow_raw_pointers()); class_("Decoder") .constructor<>() .function("addFragment", &Decoder::addFragment) .function("hasMore", &Decoder::hasMore) .function("framesLeft", &Decoder::framesLeft) .function("decode", &Decoder::decode); } #endif // WRAPPER_H