Audio-MPEG
view release on metacpan or search on metacpan
void
decode_frame(THIS, header_only = 0)
Audio_MPEG_Decode THIS
int header_only
PREINIT:
struct mad_stream *stream;
struct mad_frame *frame;
struct mad_header *header;
int err = 0;
unsigned long tagsize;
PPCODE:
stream = THIS->stream;
frame = THIS->frame;
header = &frame->header;
decode_loop:
if (mad_header_decode(header, stream) == -1) {
switch (stream->error) {
case MAD_ERROR_BUFLEN:
XSRETURN_NO;
break;
case MAD_ERROR_LOSTSYNC:
#
# Some audio formats require a header. This will generate one.
#
void
header(THIS, datasize = 0)
Audio_MPEG_Output THIS
unsigned int datasize
PREINIT:
struct audio_params *params;
PPCODE:
params = THIS->params;
switch (params->type) {
case AUDIO_MPEG_OUTPUT_TYPE_SND:
{
unsigned char header[24];
if (!datasize)
datasize = ~0; /* (unsigned) -1 */
audio_snd_header(params, datasize, header, sizeof(header));
XPUSHs(sv_2mortal(newSVpvn(header, sizeof(header))));
}
mad_fixed_t const *left = NULL;
mad_fixed_t const *right = NULL;
unsigned int pcm_len;
unsigned int delay = 0;
struct audio_params *params;
struct audio_stats *stats;
struct audio_dither_err *dither_err;
unsigned int len;
unsigned char data[MAX_NSAMPLES * sizeof(double) * 2];
mad_fixed_t mono[MAX_NSAMPLES];
PPCODE:
params = THIS->params;
stats = THIS->stats;
dither_err = THIS->dither_err;
if (!pcm->length) {
warn("pcm sample length cannot be 0");
XSRETURN_UNDEF;
}
if (! THIS->decode_delay_applied) {
THIS->decode_delay_applied = 1;
void
encode_float(THIS, pcm_sv)
Audio_MPEG_Encode THIS
SV *pcm_sv
PREINIT:
unsigned char *pcm;
STRLEN pcm_len;
unsigned int encode_len;
unsigned char out[LAME_MAXMP3BUFFER / sizeof(short) * sizeof(float)];
PPCODE:
pcm = SvPV(pcm_sv, pcm_len);
if (!pcm_len) {
warn("pcm sample length cannot be 0");
XSRETURN_UNDEF;
}
if (! THIS->encode_delay_applied) {
/* skip n input samples to compensate for encoding delay */
THIS->encode_delay_applied = 1;
pcm += THIS->flags->encoder_delay * sizeof(float) *
THIS->flags->num_channels;
void
encode16(THIS, pcm_sv)
Audio_MPEG_Encode THIS
SV *pcm_sv
PREINIT:
unsigned char *pcm;
STRLEN pcm_len;
unsigned int encode_len;
unsigned char out[LAME_MAXMP3BUFFER];
PPCODE:
pcm = SvPV(pcm_sv, pcm_len);
if (!pcm_len) {
warn("pcm sample length cannot be 0");
XSRETURN_UNDEF;
}
if (! THIS->encode_delay_applied) {
/* skip n input samples to compensate for encoding delay */
THIS->encode_delay_applied = 1;
pcm += THIS->flags->encoder_delay * sizeof(short) *
THIS->flags->num_channels;
#
# This must always be called after one thinks the encoding is finished
#
void
encode_flush(THIS)
Audio_MPEG_Encode THIS
PREINIT:
unsigned int encode_len;
unsigned char out[LAME_MAXMP3BUFFER];
PPCODE:
encode_len = lame_encode_flush(THIS->flags, out, LAME_MAXMP3BUFFER);
XPUSHs(sv_2mortal(newSVpvn(out, encode_len)));
#
# Write the Xing VBR header to an MP3 file. NOTE: file *must* be opened
# read/write!
#
void
encode_vbr_flush(THIS, fp)
( run in 0.480 second using v1.01-cache-2.11-cpan-71847e10f99 )