Lines Matching +full:high +full:- +full:quality

9  * The decoding part is based on the decoder-tutorial program madlld
88 "libmad-0",
89 "cygmad-0",
123 "libmp3lame-0",
124 "lame-enc",
125 "cygmp3lame-0",
174 "libtwolame-0",
265 #include "mp3-util.h"
276 priv_t *p = (priv_t *) ft->priv; in sox_mp3_input()
280 remaining = p->Stream.bufend - p->Stream.next_frame; in sox_mp3_input()
288 * highest observable bit-rate (currently 448 kb/s). in sox_mp3_input()
292 memmove(p->mp3_buffer, p->Stream.next_frame, remaining); in sox_mp3_input()
294 bytes_read = lsx_readbuf(ft, p->mp3_buffer+remaining, in sox_mp3_input()
295 p->mp3_buffer_size-remaining); in sox_mp3_input()
301 p->mad_stream_buffer(&p->Stream, p->mp3_buffer, bytes_read+remaining); in sox_mp3_input()
302 p->Stream.error = 0; in sox_mp3_input()
313 priv_t *p = (priv_t *) ft->priv; in sox_mp3_inputtag()
324 * recovering when Stream contains less then 8-bytes (header) in sox_mp3_inputtag()
330 remaining = p->Stream.bufend - p->Stream.next_frame; in sox_mp3_inputtag()
331 if ((tagsize = tagtype(p->Stream.this_frame, remaining))) in sox_mp3_inputtag()
333 p->mad_stream_skip(&p->Stream, tagsize); in sox_mp3_inputtag()
341 p->mad_stream_sync(&p->Stream); in sox_mp3_inputtag()
348 priv_t *p = ft->priv; in sox_mp3_vbrtag()
349 struct mad_bitptr *anc = &p->Stream.anc_ptr; in sox_mp3_vbrtag()
351 if (p->Frame.header.layer != MAD_LAYER_III) in sox_mp3_vbrtag()
354 if (p->Stream.anc_bitlen < 32) in sox_mp3_vbrtag()
357 if (!memcmp(anc->byte, "Xing", 4) || in sox_mp3_vbrtag()
358 !memcmp(anc->byte, "Info", 4)) in sox_mp3_vbrtag()
366 priv_t *p = (priv_t *) ft->priv; in startread()
368 sox_bool ignore_length = ft->signal.length == SOX_IGNORE_LENGTH; in startread()
381 p->mp3_buffer_size = sox_globals.bufsiz; in startread()
382 p->mp3_buffer = lsx_malloc(p->mp3_buffer_size); in startread()
384 ft->signal.length = SOX_UNSPEC; in startread()
385 if (ft->seekable) { in startread()
389 if (!ft->signal.length) in startread()
392 ft->signal.length = mp3_duration(ft); in startread()
395 p->mad_stream_init(&p->Stream); in startread()
396 p->mad_frame_init(&p->Frame); in startread()
397 p->mad_synth_init(&p->Synth); in startread()
398 mad_timer_reset(&p->Timer); in startread()
400 ft->encoding.encoding = SOX_ENCODING_MP3; in startread()
406 ReadSize = lsx_readbuf(ft, p->mp3_buffer, p->mp3_buffer_size); in startread()
407 if (ReadSize != p->mp3_buffer_size && lsx_error(ft)) in startread()
410 p->mad_stream_buffer(&p->Stream, p->mp3_buffer, ReadSize); in startread()
416 p->Stream.error = 0; in startread()
417 while (p->mad_frame_decode(&p->Frame,&p->Stream)) in startread()
420 if (p->Stream.error == MAD_ERROR_BUFLEN) in startread()
432 * a bunch of non-ID3 data and still haven't found a in startread()
436 p->Stream.error = 0; in startread()
439 if (p->Stream.error) in startread()
445 switch(p->Frame.header.mode) in startread()
451 ft->signal.channels = MAD_NCHANNELS(&p->Frame.header); in startread()
458 ft->signal.precision = MP3_MAD_PRECISION; in startread()
459 ft->signal.rate=p->Frame.header.samplerate; in startread()
461 ft->signal.length = SOX_UNSPEC; in startread()
463 ft->signal.length *= ft->signal.channels; /* Keep separate from line above! */ in startread()
467 p->Stream.next_frame = p->Stream.this_frame; in startread()
469 p->mad_frame_init(&p->Frame); in startread()
472 p->cursamp = 0; in startread()
478 * Read up to len samples from p->Synth
485 priv_t *p = (priv_t *) ft->priv; in sox_mp3read()
491 size_t x = (p->Synth.pcm.length - p->cursamp)*ft->signal.channels; in sox_mp3read()
495 for(chan=0;chan<ft->signal.channels;chan++){ in sox_mp3read()
496 sample=p->Synth.pcm.samples[chan][p->cursamp]; in sox_mp3read()
497 if (sample < -MAD_F_ONE) in sox_mp3read()
498 sample=-MAD_F_ONE; in sox_mp3read()
500 sample=MAD_F_ONE-1; in sox_mp3read()
501 *buf++=(sox_sample_t)(sample<<(32-1-MAD_F_FRACBITS)); in sox_mp3read()
504 p->cursamp++; in sox_mp3read()
507 len-=donow; in sox_mp3read()
513 if (p->Stream.error == MAD_ERROR_BUFLEN) in sox_mp3read()
521 if (p->mad_frame_decode(&p->Frame,&p->Stream)) in sox_mp3read()
523 if(MAD_RECOVERABLE(p->Stream.error)) in sox_mp3read()
530 if (p->Stream.error == MAD_ERROR_BUFLEN) in sox_mp3read()
535 p->mad_stream_errorstr(&p->Stream)); in sox_mp3read()
540 p->FrameCount++; in sox_mp3read()
541 p->mad_timer_add(&p->Timer,p->Frame.header.duration); in sox_mp3read()
542 p->mad_synth_frame(&p->Synth,&p->Frame); in sox_mp3read()
543 p->cursamp=0; in sox_mp3read()
551 priv_t *p=(priv_t*) ft->priv; in stopread()
553 mad_synth_finish(&p->Synth); in stopread()
554 p->mad_frame_finish(&p->Frame); in stopread()
555 p->mad_stream_finish(&p->Stream); in stopread()
557 free(p->mp3_buffer); in stopread()
564 priv_t * p = (priv_t *) ft->priv; in sox_mp3seek()
565 size_t initial_bitrate = p->Frame.header.bitrate; in sox_mp3seek()
573 mad_timer_reset(&p->Timer); in sox_mp3seek()
574 p->FrameCount = 0; in sox_mp3seek()
577 mad_synth_finish(&p->Synth); in sox_mp3seek()
578 p->mad_frame_finish(&p->Frame); in sox_mp3seek()
579 p->mad_stream_finish(&p->Stream); in sox_mp3seek()
581 p->mad_stream_init(&p->Stream); in sox_mp3seek()
582 p->mad_frame_init(&p->Frame); in sox_mp3seek()
583 p->mad_synth_init(&p->Synth); in sox_mp3seek()
585 offset /= ft->signal.channels; in sox_mp3seek()
591 size_t leftover = p->Stream.bufend - p->Stream.next_frame; in sox_mp3seek()
593 memmove(p->mp3_buffer, p->Stream.this_frame, leftover); in sox_mp3seek()
594 read = lsx_readbuf(ft, p->mp3_buffer + leftover, p->mp3_buffer_size - leftover); in sox_mp3seek()
596 …lsx_debug("seek failure. unexpected EOF (frames=%" PRIuPTR " leftover=%" PRIuPTR ")", p->FrameCoun… in sox_mp3seek()
599 for (; !depadded && padding < read && !p->mp3_buffer[padding]; ++padding); in sox_mp3seek()
601 p->mad_stream_buffer(&p->Stream, p->mp3_buffer + padding, leftover + read - padding); in sox_mp3seek()
605 p->Stream.error = MAD_ERROR_NONE; in sox_mp3seek()
608 if (p->mad_header_decode(&p->Frame.header, &p->Stream) == -1) { in sox_mp3seek()
609 if (p->Stream.error == MAD_ERROR_BUFLEN) in sox_mp3seek()
611 if (!MAD_RECOVERABLE(p->Stream.error)) { in sox_mp3seek()
615 if (p->Stream.error == MAD_ERROR_LOSTSYNC) { in sox_mp3seek()
616 unsigned available = (p->Stream.bufend - p->Stream.this_frame); in sox_mp3seek()
617 tagsize = tagtype(p->Stream.this_frame, (size_t) available); in sox_mp3seek()
620 lsx_seeki(ft, (off_t)(tagsize - available), SEEK_CUR); in sox_mp3seek()
623 p->mad_stream_skip(&p->Stream, min(tagsize, available)); in sox_mp3seek()
631 consumed += p->Stream.next_frame - p->Stream.this_frame; in sox_mp3seek()
632 vbr |= (p->Frame.header.bitrate != initial_bitrate); in sox_mp3seek()
634 samples = 32 * MAD_NSBSAMPLES(&p->Frame.header); in sox_mp3seek()
636 p->FrameCount++; in sox_mp3seek()
637 p->mad_timer_add(&p->Timer, p->Frame.header.duration); in sox_mp3seek()
641 p->mad_frame_decode(&p->Frame,&p->Stream); in sox_mp3seek()
642 p->mad_synth_frame(&p->Synth, &p->Frame); in sox_mp3seek()
643 p->cursamp = to_skip_samples; in sox_mp3seek()
646 else to_skip_samples -= samples; in sox_mp3seek()
649 if (p->FrameCount == 64 && !vbr) { in sox_mp3seek()
650 p->FrameCount = offset / samples; in sox_mp3seek()
653 … if (SOX_SUCCESS != lsx_seeki(ft, (off_t)(p->FrameCount * consumed / 64 + tagsize), SEEK_SET)) in sox_mp3seek()
657 p->mad_stream_finish(&p->Stream); in sox_mp3seek()
658 p->mad_stream_init(&p->Stream); in sox_mp3seek()
738 lsx_warn("cannot update id3 tag - failed to seek to beginning"); in get_id3v2_tag_size()
745 lsx_warn("cannot update id3 tag - failed to read id3 header"); in get_id3v2_tag_size()
746 return SOX_EOF; /* not readable, maybe opened Write-Only */ in get_id3v2_tag_size()
751 /* the tag size (minus the 10-byte header) is encoded into four in get_id3v2_tag_size()
767 priv_t *p = (priv_t *)ft->priv; in rewrite_id3v2_tag()
773 if (p->num_samples) in rewrite_id3v2_tag()
774 …lsx_warn("cannot update track length info - tag update not supported with this version of LAME. Tr… in rewrite_id3v2_tag()
776 …lsx_report("cannot update track length info - tag update not supported with this version of LAME. … in rewrite_id3v2_tag()
783 lsx_warn("cannot update track length info - failed to allocate buffer"); in rewrite_id3v2_tag()
789 lsx_warn("cannot accurately update track length info - file is too long"); in rewrite_id3v2_tag()
792 p->lame_set_num_samples(p->gfp, (unsigned long)num_samples); in rewrite_id3v2_tag()
795 new_size = p->lame_get_id3v2_tag(p->gfp, buffer, id3v2_size); in rewrite_id3v2_tag()
797 if (new_size != id3v2_size && new_size-ID3PADDING <= id3v2_size) { in rewrite_id3v2_tag()
798 p->id3tag_set_pad(p->gfp, ID3PADDING + id3v2_size - new_size); in rewrite_id3v2_tag()
799 new_size = p->lame_get_id3v2_tag(p->gfp, buffer, id3v2_size); in rewrite_id3v2_tag()
805 if (p->num_samples) in rewrite_id3v2_tag()
806 …lsx_warn("cannot update track length info - tag size adjustment not supported with this version of… in rewrite_id3v2_tag()
808 …lsx_report("cannot update track length info - tag size adjustment not supported with this version … in rewrite_id3v2_tag()
811 lsx_warn("cannot update track length info - failed to adjust tag size"); in rewrite_id3v2_tag()
825 priv_t *p = (priv_t *)ft->priv; in rewrite_tags()
831 lsx_warn("cannot update tags - seek to end failed"); in rewrite_tags()
839 lsx_warn("cannot update tags - file size is 0"); in rewrite_tags()
844 if (id3v2_size > 0 && num_samples != p->num_samples) { in rewrite_tags()
848 if (p->vbr_tag) { in rewrite_tags()
853 lsx_warn("cannot write VBR tag - seek to tag block failed"); in rewrite_tags()
857 lametag_size = p->lame_get_lametag_frame(p->gfp, buffer, sizeof(buffer)); in rewrite_tags()
859 lsx_warn("cannot write VBR tag - VBR tag too large for buffer"); in rewrite_tags()
868 lsx_warn("cannot write VBR tag - VBR tag write failed"); in rewrite_tags()
883 priv_t *p = (priv_t *) ft->priv; in startwrite()
887 if (ft->encoding.encoding != SOX_ENCODING_MP3) { in startwrite()
888 if(ft->encoding.encoding != SOX_ENCODING_UNKNOWN) in startwrite()
890 ft->encoding.encoding = SOX_ENCODING_MP3; in startwrite()
893 if(strchr(ft->filetype, '2')) in startwrite()
894 p->mp2 = 1; in startwrite()
896 if (p->mp2) { in startwrite()
926 p->mp3_buffer_size = LAME_BUFFER_SIZE(sox_globals.bufsiz / max(ft->signal.channels, 1)); in startwrite()
927 p->mp3_buffer = lsx_malloc(p->mp3_buffer_size); in startwrite()
929 p->pcm_buffer_size = sox_globals.bufsiz * sizeof(float); in startwrite()
930 p->pcm_buffer = lsx_malloc(p->pcm_buffer_size); in startwrite()
932 if (p->mp2) { in startwrite()
934 p->opt = p->twolame_init(); in startwrite()
936 if (p->opt == NULL){ in startwrite()
943 p->gfp = p->lame_init(); in startwrite()
945 if (p->gfp == NULL){ in startwrite()
951 p->lame_set_errorf(p->gfp,errorf); in startwrite()
952 p->lame_set_debugf(p->gfp,debugf); in startwrite()
953 p->lame_set_msgf (p->gfp,msgf); in startwrite()
955 …p->num_samples = ft->signal.length == SOX_IGNORE_LENGTH ? 0 : ft->signal.length / max(ft->signal.c… in startwrite()
956 p->lame_set_num_samples(p->gfp, p->num_samples > ULONG_MAX ? 0 : (unsigned long)p->num_samples); in startwrite()
960 ft->signal.precision = MP3_LAME_PRECISION; in startwrite()
962 if (ft->signal.channels != SOX_ENCODING_UNKNOWN) { in startwrite()
963 if (p->mp2) { in startwrite()
965 fail = (p->twolame_set_num_channels(p->opt,(int)ft->signal.channels) != 0); in startwrite()
969 fail = (p->lame_set_num_channels(p->gfp,(int)ft->signal.channels) < 0); in startwrite()
978 if (p->mp2) { in startwrite()
980 ft->signal.channels = p->twolame_get_num_channels(p->opt); /* Twolame default */ in startwrite()
984 ft->signal.channels = p->lame_get_num_channels(p->gfp); /* LAME default */ in startwrite()
989 if (p->mp2) { in startwrite()
991 p->twolame_set_in_samplerate(p->opt,(int)ft->signal.rate); in startwrite()
992 p->twolame_set_out_samplerate(p->opt,(int)ft->signal.rate); in startwrite()
996 p->lame_set_in_samplerate(p->gfp,(int)ft->signal.rate); in startwrite()
997 p->lame_set_out_samplerate(p->gfp,(int)ft->signal.rate); in startwrite()
1001 if (!p->mp2) { in startwrite()
1012 * The second most important parameter is probably "quality" (really in startwrite()
1013 * performance), which allows balancing encoding speed vs. quality. in startwrite()
1014 * In LAME, 0 specifies highest quality but is very slow, while in startwrite()
1015 * 9 selects poor quality, but is fast. (5 is the default and 2 is in startwrite()
1016 * recommended as a good trade-off for high quality encodes.) in startwrite()
1019 * to select quality. 128.2 selects 128 kbps encoding with a quality in startwrite()
1021 * 128 kbps encoding with default quality, so .0 means use default. Instead in startwrite()
1022 * of .0 you have to use .01 to specify the highest quality (128.01). in startwrite()
1024 * LAME uses bitrate to specify a constant bitrate, but higher quality in startwrite()
1025 * can be achieved using Variable Bit Rate (VBR). VBR quality (really in startwrite()
1026 * size) is selected using a number from 0 to 9. Use a value of 0 for high in startwrite()
1027 * quality, larger files, and 9 for smaller files of lower quality. 4 is in startwrite()
1031 * float we use negative numbers to select VRR. -4.2 would select default in startwrite()
1032 * VBR encoding (size) with high quality (speed). One special case is 0, in startwrite()
1034 * Compression value of 0 is always treated as a high quality vbr, as a in startwrite()
1035 * result both -0.2 and 0.2 are treated as highest quality VBR (size) and in startwrite()
1036 * high quality (speed). in startwrite()
1038 * Note: It would have been nice to simply use low values, 0-9, to trigger in startwrite()
1043 lsx_debug("-C option is %f", ft->encoding.compression); in startwrite()
1045 if (ft->encoding.compression == HUGE_VAL) { in startwrite()
1047 lsx_report("using %s encoding defaults", p->mp2? "MP2" : "MP3"); in startwrite()
1049 double abs_compression = fabs(ft->encoding.compression); in startwrite()
1051 double fraction_compression = abs_compression - floor_compression; in startwrite()
1055 ? -1 in startwrite()
1058 if (ft->encoding.compression < 0.5) { in startwrite()
1059 if (p->mp2) { in startwrite()
1064 if (p->lame_get_VBR(p->gfp) == vbr_off) in startwrite()
1065 p->lame_set_VBR(p->gfp, vbr_default); in startwrite()
1067 if (ft->seekable) { in startwrite()
1068 p->vbr_tag = 1; in startwrite()
1073 if (p->lame_set_VBR_q(p->gfp, bitrate_q) < 0) in startwrite()
1083 if (p->mp2) { in startwrite()
1085 fail = (p->twolame_set_brate(p->opt, bitrate_q) != 0); in startwrite()
1089 fail = (p->lame_set_brate(p->gfp, bitrate_q) < 0); in startwrite()
1094 "%slame_set_brate(%d) failed", p->mp2? "two" : "", bitrate_q); in startwrite()
1100 /* Set Quality */ in startwrite()
1102 if (encoder_q < 0 || p->mp2) { in startwrite()
1103 /* use default quality value */ in startwrite()
1104 lsx_report("using %s default quality", p->mp2? "MP2" : "MP3"); in startwrite()
1107 if (p->lame_set_quality(p->gfp, encoder_q) < 0) { in startwrite()
1117 if (!p->mp2) { in startwrite()
1119 p->lame_set_bWriteVbrTag(p->gfp, p->vbr_tag); in startwrite()
1123 if (p->mp2) { in startwrite()
1125 fail = (p->twolame_init_params(p->opt) != 0); in startwrite()
1129 fail = (p->lame_init_params(p->gfp) < 0); in startwrite()
1133 lsx_fail_errno(ft,SOX_EOF,"%s initialization failed", p->mp2? "Twolame" : "LAME"); in startwrite()
1144 priv_t *p = (priv_t *)ft->priv; in sox_mp3write()
1147 int nsamples = samp/ft->signal.channels; in sox_mp3write()
1153 if (p->pcm_buffer_size < new_buffer_size) { in sox_mp3write()
1154 float *new_buffer = lsx_realloc(p->pcm_buffer, new_buffer_size); in sox_mp3write()
1159 p->pcm_buffer_size = new_buffer_size; in sox_mp3write()
1160 p->pcm_buffer = new_buffer; in sox_mp3write()
1163 buffer_l = p->pcm_buffer; in sox_mp3write()
1165 if (p->mp2) in sox_mp3write()
1173 if (ft->signal.channels == 2) in sox_mp3write()
1178 buffer_r = p->pcm_buffer + nsamples; in sox_mp3write()
1196 if (p->mp3_buffer_size < new_buffer_size) { in sox_mp3write()
1197 unsigned char *new_buffer = lsx_realloc(p->mp3_buffer, new_buffer_size); in sox_mp3write()
1202 p->mp3_buffer_size = new_buffer_size; in sox_mp3write()
1203 p->mp3_buffer = new_buffer; in sox_mp3write()
1206 if(p->mp2) { in sox_mp3write()
1208 written = p->twolame_encode_buffer_float32_interleaved(p->opt, buffer_l, in sox_mp3write()
1209 nsamples, p->mp3_buffer, (int)p->mp3_buffer_size); in sox_mp3write()
1213 written = p->lame_encode_buffer_float(p->gfp, buffer_l, buffer_r, in sox_mp3write()
1214 nsamples, p->mp3_buffer, (int)p->mp3_buffer_size); in sox_mp3write()
1222 if (lsx_writebuf(ft, p->mp3_buffer, (size_t)written) < (size_t)written) in sox_mp3write()
1233 priv_t *p = (priv_t *) ft->priv; in stopwrite()
1234 …uint64_t num_samples = ft->olength == SOX_IGNORE_LENGTH ? 0 : ft->olength / max(ft->signal.channel… in stopwrite()
1237 if (p->mp2) { in stopwrite()
1239 written = p->twolame_encode_flush(p->opt, p->mp3_buffer, (int)p->mp3_buffer_size); in stopwrite()
1243 written = p->lame_encode_flush(p->gfp, p->mp3_buffer, (int)p->mp3_buffer_size); in stopwrite()
1248 else if (lsx_writebuf(ft, p->mp3_buffer, (size_t)written) < (size_t)written) in stopwrite()
1250 else if (!p->mp2) { in stopwrite()
1252 if (ft->seekable && (num_samples != p->num_samples || p->vbr_tag)) in stopwrite()
1257 free(p->mp3_buffer); in stopwrite()
1258 free(p->pcm_buffer); in stopwrite()
1260 if(p->mp2) { in stopwrite()
1262 p->twolame_close(&p->opt); in stopwrite()
1267 p->lame_close(p->gfp); in stopwrite()