diff options
| -rw-r--r-- | src/rmd_encode_audio_buffers.c | 73 | 
1 files changed, 31 insertions, 42 deletions
diff --git a/src/rmd_encode_audio_buffers.c b/src/rmd_encode_audio_buffers.c index 9a4a16a..a5d350f 100644 --- a/src/rmd_encode_audio_buffers.c +++ b/src/rmd_encode_audio_buffers.c @@ -37,9 +37,35 @@  #include <errno.h> +static void rmdEncodeAudioBuffer(ProgData *pdata, void *buff) +{ +	int	sampread = (buff != NULL) ? pdata->periodsize : 0; +	float	**vorbis_buffer = vorbis_analysis_buffer(&pdata->enc_data->m_vo_dsp, sampread); + +	if (!pdata->args.use_jack) { +		for (int i = 0, count = 0; i < sampread; i++) { +			for (int j = 0; j < pdata->args.channels; j++) { +				vorbis_buffer[j][i] =	((((signed char *)buff)[count + 1] << 8) | +							(0x00ff & (int)((signed char *)buff)[count])) +							/ 32768.f; +				count += 2; +			} +		} +	} else { +		for (int j = 0, count = 0; j < pdata->args.channels; j++) { +			for (int i = 0; i < sampread; i++) { +				vorbis_buffer[j][i] = ((float *)buff)[count]; +				count++; +			} +		} +	} + +	vorbis_analysis_wrote(&pdata->enc_data->m_vo_dsp, sampread); +} + +  void *rmdEncodeAudioBuffers(ProgData *pdata)  { -	int	sampread = pdata->periodsize;  #ifdef HAVE_LIBJACK  	void	*jackbuf = NULL; @@ -51,7 +77,6 @@ void *rmdEncodeAudioBuffers(ProgData *pdata)  	pdata->v_encoding_clean = 0;  	while (pdata->running) { -		float		**vorbis_buffer;  		SndBuffer	*buff = NULL;  		pthread_mutex_lock(&pdata->pause_mutex); @@ -72,16 +97,8 @@ void *rmdEncodeAudioBuffers(ProgData *pdata)  			if (!pdata->running)  				break; -			vorbis_buffer = vorbis_analysis_buffer(&pdata->enc_data->m_vo_dsp, sampread); +			rmdEncodeAudioBuffer(pdata, buff); -			for (int i = 0, count = 0; i < sampread; i++) { -				for (int j = 0; j < pdata->args.channels; j++) { -					vorbis_buffer[j][i] =	((buff->data[count + 1] << 8) | -								(0x00ff & (int)buff->data[count])) / -								32768.f; -					count += 2; -				} -			}  			free(buff->data);  			free(buff);  		} else { @@ -105,17 +122,9 @@ void *rmdEncodeAudioBuffers(ProgData *pdata)  			if (!pdata->running)  				break; -			vorbis_buffer = vorbis_analysis_buffer(&pdata->enc_data->m_vo_dsp, sampread); - -			for (int j = 0, count = 0; j < pdata->args.channels; j++) { -				for (int i = 0; i < sampread; i++) { -					vorbis_buffer[j][i] = ((float*)jackbuf)[count]; -					count++; -				} -			} +			rmdEncodeAudioBuffer(pdata, jackbuf);  #endif  		} -		vorbis_analysis_wrote(&pdata->enc_data->m_vo_dsp, sampread);  		pthread_mutex_lock(&pdata->libogg_mutex);  		while (vorbis_analysis_blockout(&pdata->enc_data->m_vo_dsp, &pdata->enc_data->m_vo_block) == 1) { @@ -136,30 +145,10 @@ void *rmdEncodeAudioBuffers(ProgData *pdata)  	pthread_exit(&errno);  } +  void rmdSyncEncodeAudioBuffer(ProgData *pdata, signed char *buff)  { -	int	sampread = (buff != NULL) ? pdata->periodsize : 0; -	float	**vorbis_buffer = vorbis_analysis_buffer(&pdata->enc_data->m_vo_dsp, sampread); - -	if (!pdata->args.use_jack) { -		for (int i = 0, count = 0; i < sampread; i++) { -			for (int j = 0; j < pdata->args.channels; j++) { -				vorbis_buffer[j][i] =	((buff[count + 1] << 8) | -							(0x00ff & (int)buff[count])) -							/ 32768.f; -				count += 2; -			} -		} -	} else { -		for (int j = 0, count = 0; j < pdata->args.channels; j++) { -			for (int i = 0; i < sampread; i++) { -				vorbis_buffer[j][i] = ((float *)buff)[count]; -				count++; -			} -		} -	} - -	vorbis_analysis_wrote(&pdata->enc_data->m_vo_dsp, sampread); +	rmdEncodeAudioBuffer(pdata, buff);  	pthread_mutex_lock(&pdata->libogg_mutex);  	while (vorbis_analysis_blockout(&pdata->enc_data->m_vo_dsp, &pdata->enc_data->m_vo_block) == 1) {  | 
