jsmad/wrapper.cpp

73 lines
1.6 KiB
C++
Raw Normal View History

2018-12-27 15:29:06 +00:00
#include "wrapper.h"
2018-12-29 12:39:49 +00:00
#include <string>
#include <iostream>
2018-12-27 15:29:06 +00:00
MadHeader * mad_header_create()
{
MadHeader* header = new MadHeader;
mad_header_init(header);
return header;
}
MadFrame * mad_frame_create()
{
MadFrame* frame = new MadFrame;
mad_frame_init(frame);
return frame;
}
emscripten::val MadFrame::getOverlap() const
{
2018-12-29 12:39:49 +00:00
unsigned char* ptr = (unsigned char(*))*overlap;
2018-12-27 15:29:06 +00:00
return emscripten::val(typed_memory_view(sizeof *overlap, ptr));
}
emscripten::val MadFrame::getSbsample() const
{
2018-12-29 12:39:49 +00:00
unsigned char* ptr = (unsigned char(*))sbsample;
2018-12-27 15:29:06 +00:00
return emscripten::val(typed_memory_view(sizeof sbsample, ptr));
}
MadStream* mad_stream_create() {
MadStream* stream = new MadStream;
mad_stream_init(stream);
return stream;
}
emscripten::val MadStream::mainData()
{
return emscripten::val(typed_memory_view(MAD_BUFFER_MDLEN, (unsigned char(*))main_data));
}
void MadStream::setBuffer(intptr_t bufferPtr, unsigned long length)
{
mad_stream_buffer(this, (const unsigned char(*))bufferPtr, length);
}
int MadFrame::decode(mad_stream* stream)
{
return mad_frame_decode(this, stream);
}
2018-12-29 12:39:49 +00:00
emscripten::val MadPCM::samples() const
{
mad_fixed_t* ptr = (mad_fixed_t(*))mad_pcm::samples;
return emscripten::val(typed_memory_view(sizeof mad_pcm::samples, ptr));
}
MadPCM* mad_pcm_create() {
MadPCM* pcm = new MadPCM();
return pcm;
}
MadSynth* mad_synth_create() {
MadSynth* synth = new MadSynth();
mad_synth_init(synth);
return synth;
}
void MadSynth::frame(const mad_frame* frame)
{
mad_synth_frame(this, frame);
}