Audio-Mad
view release on metacpan or search on metacpan
init(THIS, oldrate=0, newrate=0)
Audio_Mad_Resample THIS
unsigned int oldrate
unsigned int newrate
CODE:
mad_resample_init(THIS, oldrate, newrate);
RETVAL = THIS->mode;
OUTPUT:
RETVAL
unsigned int
mode(THIS)
Audio_Mad_Resample THIS
CODE:
RETVAL = THIS->mode;
OUTPUT:
RETVAL
void
resample(THIS, left, right=&PL_sv_undef)
Audio_Mad_Resample THIS
SV *left
SV *right
PREINIT:
unsigned int length, old_length, bufsize;
mad_fixed_t *resampled, *data;
double fscale;
PPCODE:
if (!SvPOK(left)) {
XSRETURN_UNDEF;
}
/* this scale value, and the following calculation
based upon it are gross displays of my infantile
C programming abilities. basically, I found out
the buffer _grows_ when you _upscale_ -- imagine
that (*smacks self*). */
fscale = mad_f_todouble(THIS->ratio);
old_length = SvLEN(left) / sizeof(mad_fixed_t);
/* so I spent an hour or two, and thought of this
method of approximating a resulting buffer size
based upon the ratio scale value, above. If
there is a better way, let me know. This
can't be a good way of doing this. */
bufsize = old_length * ((int)((double)1 / fscale) + 1);
data = (mad_fixed_t *)SvPV_nolen(left);
Newz(0, (void *)resampled, bufsize, mad_fixed_t);
length = mad_resample_block(THIS, &THIS->state[0], old_length, data, resampled);
PUSHs(sv_2mortal(newSVpvn((char *)resampled, sizeof(mad_fixed_t) * length)));
if (right != &PL_sv_undef) {
if (!SvPOK(right)) {
XSRETURN_UNDEF;
}
old_length = SvLEN(right) / sizeof(mad_fixed_t);
bufsize = old_length * ((int)((double)1 / fscale) + 1);
/* ugh.. that always looks ugly.. but it works */
data = (mad_fixed_t *)SvPV_nolen(right);
Renew((void *)resampled, bufsize, mad_fixed_t);
length = mad_resample_block(THIS, &THIS->state[1], old_length, data, resampled);
PUSHs(sv_2mortal(newSVpvn((char *)resampled, sizeof(mad_fixed_t) * length)));
}
Safefree((void *)resampled);
void
DESTROY(THIS)
Audio_Mad_Resample THIS;
CODE:
Safefree(THIS);
XSRETURN_UNDEF;
MODULE = Audio::Mad PACKAGE = Audio::Mad::Dither
Audio_Mad_Dither
new(CLASS, type=MAD_DITHER_S16_LE)
char *CLASS = NO_INIT;
int type
CODE:
Newz(0, (void *)RETVAL, sizeof(*RETVAL), char);
mad_dither_init(RETVAL, type);
OUTPUT:
RETVAL
void
init(THIS, type=MAD_DITHER_S16_LE)
Audio_Mad_Dither THIS
int type
CODE:
mad_dither_init(THIS, type);
XSRETURN_UNDEF;
void
dither(THIS, leftsv, rightsv=&PL_sv_undef)
Audio_Mad_Dither THIS
SV *leftsv
SV *rightsv
PREINIT:
STRLEN old_length, length;
mad_fixed_t *left, *right = NULL;
unsigned char *cooked;
PPCODE:
if (THIS->pcmfunc == NULL) {
XSRETURN_UNDEF;
}
if (!SvPOK(leftsv)) {
XSRETURN_UNDEF;
}
old_length = SvLEN(leftsv) / sizeof(mad_fixed_t);
left = (mad_fixed_t *)SvPV_nolen(leftsv);
if (!SvPOK(rightsv)) {
length = old_length * THIS->pcmlength;
Newz(0, (void *)cooked, length, char);
( run in 1.354 second using v1.01-cache-2.11-cpan-364913b4093 )