Skip to content

Commit

Permalink
Big update provided by Janne Hyvärinen (Case).
Browse files Browse the repository at this point in the history
Changes include:

* fixed pipe encoding missing the beginning of the audio and breaking gaplessness.
* fixed the encoder to not read data beyond data chunk.
* added support for 24 bit integer and 32 bit integer and floating point input data.
* added Unicode filename support for input and output files.
* added support for WAVE_FORMAT_EXTENSIBLE file format and RIFX big endian WAVE files.
* Made encoder reject input tracks with zero samples.
* Added support for printing unicode filenames to the console.
* Fixed gapless data saving, the encoder tried to store too long numbers in padding info fields and the numbers got truncated as the storage space is only 12 bits long.
* Fixed internal resampling to produce output with correct lengths.
* Fixed encoding WAV files with huge headers.
* Fixed writing empty track when input had unsupported sample rate.
* Added more detailed error message for input file rejection if the audio specs weren't supported.
  • Loading branch information
maikmerten committed Mar 20, 2024
1 parent 39f3d1c commit 6d57f3f
Show file tree
Hide file tree
Showing 17 changed files with 791 additions and 489 deletions.
6 changes: 3 additions & 3 deletions hmp3/src/bitallo.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* ***** BEGIN LICENSE BLOCK *****
* Source last modified: $Id: bitallo.cpp,v 1.1 2005/07/13 17:22:20 rggammon Exp $
* Source last modified: 2024-03-14, Case
*
* Portions Copyright (c) 1995-2005 RealNetworks, Inc. All Rights Reserved.
*
Expand Down Expand Up @@ -45,9 +45,9 @@ block_type ( 0 )
{
}

CBitAllo::~CBitAllo ( )
/*CBitAllo::~CBitAllo ( )
{
}
}*/

//======================================================
int
Expand Down
4 changes: 2 additions & 2 deletions hmp3/src/bitallo3.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* ***** BEGIN LICENSE BLOCK *****
* Source last modified: $Id: bitallo3.cpp,v 1.2 2005/08/09 20:43:41 karll Exp $
* Source last modified: 2024-03-14, Case
*
* Portions Copyright (c) 1995-2005 RealNetworks, Inc. All Rights Reserved.
*
Expand Down Expand Up @@ -901,7 +901,7 @@ CBitAllo3::startup ( SIG_MASK sm[][36], unsigned char signx[][576] )
void
CBitAllo3::startup_ms2 ( SIG_MASK sm[][36], unsigned char signx[][576] )
{
int i, n, ch;
int i, n=0, ch;
int mnr;
float *x, *y;
unsigned char *s;
Expand Down
4 changes: 2 additions & 2 deletions hmp3/src/filter2.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* ***** BEGIN LICENSE BLOCK *****
* Source last modified: $Id: filter2.c,v 1.1 2005/07/13 17:22:20 rggammon Exp $
* Source last modified: 2024-03-16, Case
*
* Portions Copyright (c) 1995-2005 RealNetworks, Inc. All Rights Reserved.
*
Expand Down Expand Up @@ -77,7 +77,7 @@ filter2_init ( int samprate, int filter_select,

/*--------------------------------------------------------------------*/
void
filter2 ( short pcm[], float *buf1, float *buf2, FILTER2_CONTROL * fc2 )
filter2 ( float pcm[], float *buf1, float *buf2, FILTER2_CONTROL * fc2 )
{
int i;
float *x, *y;
Expand Down
48 changes: 22 additions & 26 deletions hmp3/src/mp3enc.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* ***** BEGIN LICENSE BLOCK *****
* Source last modified: 2022-11-21, Maik Merten
* Source last modified: 2024-03-17, Case
*
* Portions Copyright (c) 1995-2005 RealNetworks, Inc. All Rights Reserved.
*
Expand Down Expand Up @@ -592,7 +592,7 @@ CMp3Enc::L3_audio_encode_init ( E_CONTROL * ec_arg )
/*------- input filter function selection ----*/
filter2_init ( samprate, ec.filter_select, monodual, &fc2 );

bytes_in = ( 1 + monodual ) * ( sizeof ( short ) * 1152 );
bytes_in = ( 1 + monodual ) * ( sizeof ( float ) * 1152 );

/*--- init encoder tables ----*/

Expand Down Expand Up @@ -2028,7 +2028,7 @@ CMp3Enc::encode_singleB_MPEG2 ( )

/*====================================================================*/
IN_OUT
CMp3Enc::L3_audio_encode ( short *pcm, unsigned char *bs_out )
CMp3Enc::L3_audio_encode ( float *pcm, unsigned char *bs_out )
{

switch ( iL3_audio_encode_function )
Expand All @@ -2048,7 +2048,7 @@ CMp3Enc::L3_audio_encode ( short *pcm, unsigned char *bs_out )

/*====================================================================*/
IN_OUT
CMp3Enc::L3_audio_encode_Packet ( short *pcm,
CMp3Enc::L3_audio_encode_Packet ( float *pcm,
unsigned char *bs_out,
unsigned char *packet, int nbytes_out[2] )
{
Expand Down Expand Up @@ -2103,7 +2103,7 @@ CMp3Enc::L3_pack_head_vbr ( unsigned char *bs_out,

/*====================================================================*/
IN_OUT
CMp3Enc::L3_audio_encode_vbr_MPEG1 ( short *pcm, unsigned char *bs_out )
CMp3Enc::L3_audio_encode_vbr_MPEG1 ( float *pcm, unsigned char *bs_out )
{
IN_OUT x;
int bytes;
Expand Down Expand Up @@ -2227,7 +2227,7 @@ CMp3Enc::L3_audio_encode_vbr_MPEG1 ( short *pcm, unsigned char *bs_out )

/*====================================================================*/
IN_OUT
CMp3Enc::L3_audio_encode_MPEG1 ( short *pcm, unsigned char *bs_out )
CMp3Enc::L3_audio_encode_MPEG1 ( float *pcm, unsigned char *bs_out )
{
IN_OUT x;
int bytes;
Expand Down Expand Up @@ -2334,7 +2334,7 @@ CMp3Enc::L3_audio_encode_MPEG1 ( short *pcm, unsigned char *bs_out )

/*====================================================================*/
IN_OUT
CMp3Enc::L3_audio_encode_vbr_MPEG2 ( short *pcm, unsigned char *bs_out )
CMp3Enc::L3_audio_encode_vbr_MPEG2 ( float *pcm, unsigned char *bs_out )
{
IN_OUT x;
int bytes, bytes2, bytes3;
Expand Down Expand Up @@ -2480,7 +2480,7 @@ CMp3Enc::L3_audio_encode_vbr_MPEG2 ( short *pcm, unsigned char *bs_out )

/*====================================================================*/
IN_OUT
CMp3Enc::L3_audio_encode_MPEG2 ( short *pcm, unsigned char *bs_out )
CMp3Enc::L3_audio_encode_MPEG2 ( float *pcm, unsigned char *bs_out )
{
IN_OUT x;
int bytes;
Expand Down Expand Up @@ -2652,14 +2652,13 @@ find_nearest ( const int *table, int n, int x )

/*==================================================================*/
int
CMp3Enc::MP3_audio_encode_init ( E_CONTROL * ec_arg, int input_type, // 0=16 bit linear,1=8 bitlinear
CMp3Enc::MP3_audio_encode_init ( E_CONTROL * ec_arg, int source_bits, int source_is_float,
int mpeg_select, int mono_convert )
{
E_CONTROL ec;
E_CONTROL ec2;
int source, target;
int source_chan, target_chan;
int source_bits;
int convert_flag;
int encode_input_bytes;
int encode_cutoff_freq;
Expand Down Expand Up @@ -2699,10 +2698,6 @@ CMp3Enc::MP3_audio_encode_init ( E_CONTROL * ec_arg, int input_type, // 0=16
if ( mono_convert )
target_chan = 1;

source_bits = 16;
if ( input_type == 1 )
source_bits = 8;

/*------ determine encode sample rate --------*/
if ( mpeg_select < 0 )
mpeg_select = 0;
Expand Down Expand Up @@ -2755,21 +2750,23 @@ CMp3Enc::MP3_audio_encode_init ( E_CONTROL * ec_arg, int input_type, // 0=16
}

/*--- determine if conversion required */
convert_flag = 0; // assume no conversion
if ( source_bits != 16 )
convert_flag = 1; // conversion always needed
/*
if ( !(source_bits == 32 && source_is_float) )
convert_flag = 1;
if ( source != target )
convert_flag = 1;
if ( source_chan != target_chan )
convert_flag = 1;
*/

/*--- init sample rate conversion ---*/
nsb_limit = -1; // use nsb limit because of L3 low rate auto limit logic
if ( convert_flag )
{
src = new Csrc; // sample rate conversion
min_input_bytes =
src->sr_convert_init ( source, source_chan, source_bits, target,
src->sr_convert_init ( source, source_chan, source_bits, source_is_float, target,
target_chan, &encode_cutoff_freq );
if ( min_input_bytes <= 0 )
return 0; // conversion init failed
Expand Down Expand Up @@ -2804,8 +2801,8 @@ CMp3Enc::MP3_audio_encode_init ( E_CONTROL * ec_arg, int input_type, // 0=16
/*-- select converter/encoder combination --*/
//encode = L3_convert_encode;
src_encode = 1;
src_pcmbuf = new short[2304];
memset ( src_pcmbuf, 0, 2304 * sizeof ( short ) );
src_pcmbuf = new float[2304];
memset ( src_pcmbuf, 0, 2304 * sizeof (float) );

return min_input_bytes;
}
Expand All @@ -2818,7 +2815,7 @@ CMp3Enc::MP3_audio_encode ( unsigned char *pcm, unsigned char *bs_out )

if ( src_encode == 0 )
{
return L3_audio_encode ( ( short * ) pcm, bs_out );
return L3_audio_encode ( ( float * ) pcm, bs_out );
}
else
{
Expand All @@ -2840,7 +2837,7 @@ CMp3Enc::MP3_audio_encode_Packet ( unsigned char *pcm,

if ( src_encode == 0 )
{
return L3_audio_encode_Packet ( ( short * ) pcm, bs_out,
return L3_audio_encode_Packet ( ( float * ) pcm, bs_out,
packet, nbytes_out );
}
else
Expand Down Expand Up @@ -2868,7 +2865,7 @@ CMp3Enc::MP3_audio_encode_Packet ( unsigned char *pcm,

/*====================================================================*/
IN_OUT
CMp3Enc::L3_audio_encode_vbr_MPEG1Packet ( short *pcm,
CMp3Enc::L3_audio_encode_vbr_MPEG1Packet ( float *pcm,
unsigned char *bs_out,
unsigned char *packet,
int nbytes_out[2] )
Expand Down Expand Up @@ -3014,7 +3011,7 @@ CMp3Enc::L3_audio_encode_vbr_MPEG1Packet ( short *pcm,

/*====================================================================*/
IN_OUT
CMp3Enc::L3_audio_encode_MPEG1Packet ( short *pcm,
CMp3Enc::L3_audio_encode_MPEG1Packet ( float *pcm,
unsigned char *bs_out,
unsigned char *packet,
int nbytes_out[2] )
Expand Down Expand Up @@ -3137,7 +3134,7 @@ CMp3Enc::L3_audio_encode_MPEG1Packet ( short *pcm,

/*====================================================================*/
IN_OUT
CMp3Enc::L3_audio_encode_vbr_MPEG2Packet ( short *pcm,
CMp3Enc::L3_audio_encode_vbr_MPEG2Packet ( float *pcm,
unsigned char *bs_out,
unsigned char *packet,
int nbytes_out[2] )
Expand Down Expand Up @@ -3301,7 +3298,7 @@ CMp3Enc::L3_audio_encode_vbr_MPEG2Packet ( short *pcm,

/*====================================================================*/
IN_OUT
CMp3Enc::L3_audio_encode_MPEG2Packet ( short *pcm,
CMp3Enc::L3_audio_encode_MPEG2Packet ( float *pcm,
unsigned char *bs_out,
unsigned char *packet,
int nbytes_out[2] )
Expand Down Expand Up @@ -3479,7 +3476,6 @@ CMp3Enc::L3_audio_encode_get_bitrate2_float ( )
samprate;

return br;

}

/*--------------------------------------------------------------------*/
Expand Down

0 comments on commit 6d57f3f

Please sign in to comment.