for( unsigned j = 0; j < i_samples; j++ )
for( unsigned i = 0; i < i_nb_channels; i++ )
- p_out[j * i_nb_channels + i] = pp_in[pi_index[i]][j] << shift;
+ {
+ union { int32_t i; uint32_t u; } spl;
+
+ spl.u = ((uint32_t)pp_in[pi_index[i]][j]) << shift;
+ p_out[j * i_nb_channels + i] = spl.i;
+ }
}
/*****************************************************************************
p_dec->fmt_out.audio.i_physical_channels =
p_dec->fmt_out.audio.i_original_channels =
pi_channels_maps[metadata->data.stream_info.channels];
- p_dec->fmt_out.audio.i_bitspersample =
- metadata->data.stream_info.bits_per_sample;
+ if (!p_dec->fmt_out.audio.i_bitspersample)
+ p_dec->fmt_out.audio.i_bitspersample =
+ metadata->data.stream_info.bits_per_sample;
msg_Dbg( p_dec, "channels:%d samplerate:%d bitspersamples:%d",
p_dec->fmt_out.audio.i_channels, p_dec->fmt_out.audio.i_rate,
msg_Err( p_dec, "frame's data did not match the CRC in the "
"footer." );
break;
+ case FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM:
+ msg_Err( p_dec, "The decoder encountered reserved fields in use in "
+ "the stream." );
+ break;
default:
msg_Err( p_dec, "got decoder error: %d", status );
}
/* Decode STREAMINFO */
msg_Dbg( p_dec, "decode STREAMINFO" );
size_t i_extra = p_dec->fmt_in.i_extra;
+ static const char header[4] = { 'f', 'L', 'a', 'C' };
+
+ if (i_extra > 42 && !memcmp(p_dec->fmt_in.p_extra, header, 4))
+ i_extra = 42;
+ else if (i_extra > 34 && memcmp(p_dec->fmt_in.p_extra, header, 4))
+ i_extra = 34;
+
switch (i_extra) {
case 34:
p_sys->p_block = block_Alloc( 8 + i_extra );
memcpy( p_sys->p_block->p_buffer + 8, p_dec->fmt_in.p_extra, i_extra );
- memcpy( p_sys->p_block->p_buffer, "fLaC", 4);
+ memcpy( p_sys->p_block->p_buffer, header, 4);
uint8_t *p = p_sys->p_block->p_buffer;
p[4] = 0x80 | 0; /* STREAMINFO faked as last block */
p[5] = 0;
msg_Dbg( p_enc, "Writing STREAMINFO: %zu", bytes );
/* Backup the STREAMINFO metadata block */
- p_enc->fmt_out.i_extra = STREAMINFO_SIZE;
- p_enc->fmt_out.p_extra = xmalloc( STREAMINFO_SIZE );
- memcpy(p_enc->fmt_out.p_extra, buffer + 4, STREAMINFO_SIZE );
+ p_enc->fmt_out.i_extra = STREAMINFO_SIZE + 8;
+ p_enc->fmt_out.p_extra = xmalloc( STREAMINFO_SIZE + 8);
+ memcpy(p_enc->fmt_out.p_extra, "fLaC", 4);
+ memcpy((uint8_t*)p_enc->fmt_out.p_extra + 4, buffer, STREAMINFO_SIZE );
+ /* Fake this as the last metadata block */
+ ((uint8_t*)p_enc->fmt_out.p_extra)[4] |= 0x80;
}
p_sys->i_headers++;
- return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
+ return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
}
p_block = block_Alloc( bytes );
block_ChainAppend( &p_sys->p_chain, p_block );
- return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
+ return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
}
/*****************************************************************************
* EncoderMetadataCallback: called by libflac to output metadata
p_sys->i_samples_delay += p_aout_buf->i_nb_samples;
/* Convert samples to FLAC__int32 */
- if( p_sys->i_buffer < p_aout_buf->i_buffer * 2 )
+ if( p_sys->i_buffer < p_aout_buf->i_buffer * sizeof(FLAC__int32) )
{
p_sys->p_buffer =
- xrealloc( p_sys->p_buffer, p_aout_buf->i_buffer * 2 );
+ xrealloc( p_sys->p_buffer, p_aout_buf->i_buffer * sizeof(FLAC__int32) );
p_sys->i_buffer = p_aout_buf->i_buffer * 2;
}