Skip to content

Commit

Permalink
(libretro-common) Create libretro-common/conversion/float_to_s16
Browse files Browse the repository at this point in the history
  • Loading branch information
inactive123 committed May 16, 2016
1 parent d7b28d3 commit 2422dfb
Show file tree
Hide file tree
Showing 13 changed files with 388 additions and 270 deletions.
6 changes: 4 additions & 2 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,11 @@ ifeq ($(HAVE_NEON),1)
DEFINES += -DSINC_LOWER_QUALITY
endif

OBJ += audio/audio_utils.o
OBJ += audio/audio_utils.o \
libretro-common/conversion/float_to_s16.o
ifeq ($(HAVE_NEON),1)
OBJ += audio/audio_utils_neon.o
OBJ += audio/audio_utils_neon.o \
libretro-common/conversion/float_to_s16_neon.o
endif

HW_CONTEXT_MENU_DRIVERS=$(HAVE_RGUI)
Expand Down
2 changes: 1 addition & 1 deletion Makefile.openpandora
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ TARGET := retroarch-pandora
LDDIRS = -L. -L$(PNDSDK)/usr/lib
INCDIRS = -I. -I$(PNDSDK)/usr/include

OBJ = griffin/griffin.o audio/resamplers/sinc_resampler_neon.o audio/audio_utils_neon.o
OBJ = griffin/griffin.o audio/resamplers/sinc_resampler_neon.o audio/audio_utils_neon.o libretro-common/conversion/float_to_s16_neon.o
LDFLAGS = -L$(PNDSDK)/usr/lib -Wl,-rpath,$(PNDSDK)/usr/lib

LIBS = -lGLESv2 -lEGL -ldl -lm -lpthread -lrt -lasound
Expand Down
3 changes: 2 additions & 1 deletion audio/audio_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <retro_assert.h>

#include <lists/string_list.h>
#include <conversion/float_to_s16.h>

#include "audio_driver.h"
#include "audio_resampler_driver.h"
Expand Down Expand Up @@ -581,7 +582,7 @@ static bool audio_driver_flush(const int16_t *data, size_t samples)
{
performance_counter_init(&audio_convert_float, "audio_convert_float");
performance_counter_start(&audio_convert_float);
audio_convert_float_to_s16(audio_driver_data.output_samples.conv_buf,
convert_float_to_s16(audio_driver_data.output_samples.conv_buf,
(const float*)output_data, output_frames * 2);
performance_counter_stop(&audio_convert_float);

Expand Down
167 changes: 2 additions & 165 deletions audio/audio_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <boolean.h>
#include <features/features_cpu.h>
#include <conversion/float_to_s16.h>

#include "audio_utils.h"

Expand Down Expand Up @@ -49,28 +50,6 @@ void audio_convert_s16_to_float_C(float *out,
out[i] = (float)in[i] * gain;
}

/**
* audio_convert_float_to_s16_C:
* @out : output buffer
* @in : input buffer
* @samples : size of samples to be converted
*
* Converts audio samples from floating point
* to signed integer 16-bit.
*
* C implementation callback function.
**/
void audio_convert_float_to_s16_C(int16_t *out,
const float *in, size_t samples)
{
size_t i;
for (i = 0; i < samples; i++)
{
int32_t val = (int32_t)(in[i] * 0x8000);
out[i] = (val > 0x7FFF) ? 0x7FFF :
(val < -0x8000 ? -0x8000 : (int16_t)val);
}
}

#if defined(__SSE2__)
/**
Expand Down Expand Up @@ -107,38 +86,6 @@ void audio_convert_s16_to_float_SSE2(float *out,
audio_convert_s16_to_float_C(out, in, samples - i, gain);
}

/**
* audio_convert_float_to_s16_SSE2:
* @out : output buffer
* @in : input buffer
* @samples : size of samples to be converted
*
* Converts audio samples from floating point
* to signed integer 16-bit.
*
* SSE2 implementation callback function.
**/
void audio_convert_float_to_s16_SSE2(int16_t *out,
const float *in, size_t samples)
{
size_t i;
__m128 factor = _mm_set1_ps((float)0x8000);

for (i = 0; i + 8 <= samples; i += 8, in += 8, out += 8)
{
__m128 input_l = _mm_loadu_ps(in + 0);
__m128 input_r = _mm_loadu_ps(in + 4);
__m128 res_l = _mm_mul_ps(input_l, factor);
__m128 res_r = _mm_mul_ps(input_r, factor);
__m128i ints_l = _mm_cvtps_epi32(res_l);
__m128i ints_r = _mm_cvtps_epi32(res_r);
__m128i packed = _mm_packs_epi32(ints_l, ints_r);

_mm_storeu_si128((__m128i *)out, packed);
}

audio_convert_float_to_s16_C(out, in, samples - i);
}
#elif defined(__ALTIVEC__)
/**
* audio_convert_s16_to_float_altivec:
Expand Down Expand Up @@ -182,40 +129,6 @@ void audio_convert_s16_to_float_altivec(float *out,
audio_convert_s16_to_float_C(out, in, samples_in, gain);
}

/**
* audio_convert_float_to_s16_altivec:
* @out : output buffer
* @in : input buffer
* @samples : size of samples to be converted
*
* Converts audio samples from floating point
* to signed integer 16-bit.
*
* AltiVec implementation callback function.
**/
void audio_convert_float_to_s16_altivec(int16_t *out,
const float *in, size_t samples)
{
int samples_in = samples;

/* Unaligned loads/store is a bit expensive,
* so we optimize for the good path (very likely). */
if (((uintptr_t)out & 15) + ((uintptr_t)in & 15) == 0)
{
size_t i;
for (i = 0; i + 8 <= samples; i += 8, in += 8, out += 8)
{
vector float input0 = vec_ld( 0, in);
vector float input1 = vec_ld(16, in);
vector signed int result0 = vec_cts(input0, 15);
vector signed int result1 = vec_cts(input1, 15);
vec_st(vec_packs(result0, result1), 0, out);
}

samples_in -= i;
}
audio_convert_float_to_s16_C(out, in, samples_in);
}
#elif defined(__ARM_NEON__) && !defined(VITA)
/* Avoid potential hard-float/soft-float ABI issues. */
void audio_convert_s16_float_asm(float *out, const int16_t *in,
Expand Down Expand Up @@ -244,30 +157,6 @@ static void audio_convert_s16_to_float_neon(float *out,
audio_convert_s16_to_float_C(out + aligned_samples, in + aligned_samples,
samples - aligned_samples, gain);
}

void audio_convert_float_s16_asm(int16_t *out, const float *in, size_t samples);

/**
* audio_convert_float_to_s16_neon:
* @out : output buffer
* @in : input buffer
* @samples : size of samples to be converted
*
* Converts audio samples from floating point
* to signed integer 16-bit.
*
* ARM NEON implementation callback function.
**/
static void audio_convert_float_to_s16_neon(int16_t *out,
const float *in, size_t samples)
{
size_t aligned_samples = samples & ~7;
if (aligned_samples)
audio_convert_float_s16_asm(out, in, aligned_samples);

audio_convert_float_to_s16_C(out + aligned_samples, in + aligned_samples,
samples - aligned_samples);
}
#elif defined(_MIPS_ARCH_ALLEGREX)

/**
Expand Down Expand Up @@ -340,58 +229,6 @@ void audio_convert_s16_to_float_ALLEGREX(float *out,
for (; i < samples; i++)
out[i] = (float)in[i] * gain;
}

/**
* audio_convert_float_to_s16_ALLEGREX:
* @out : output buffer
* @in : input buffer
* @samples : size of samples to be converted
*
* Converts audio samples from floating point
* to signed integer 16-bit.
*
* MIPS ALLEGREX implementation callback function.
**/
void audio_convert_float_to_s16_ALLEGREX(int16_t *out,
const float *in, size_t samples)
{
size_t i;

#ifdef DEBUG
/* Make sure the buffers are 16 byte aligned, this should be
* the default behaviour of malloc in the PSPSDK.
* Both buffers are allocated by RetroArch, so can assume alignment. */
retro_assert(((uintptr_t)in & 0xf) == 0);
retro_assert(((uintptr_t)out & 0xf) == 0);
#endif

for (i = 0; i + 8 <= samples; i += 8)
{
__asm__ (
".set push \n"
".set noreorder \n"

"lv.q c100, 0(%0) \n"
"lv.q c110, 16(%0) \n"

"vf2in.q c100, c100, 31 \n"
"vf2in.q c110, c110, 31 \n"
"vi2s.q c100, c100 \n"
"vi2s.q c102, c110 \n"

"sv.q c100, 0(%1) \n"

".set pop \n"
:: "r"(in + i), "r"(out + i));
}

for (; i < samples; i++)
{
int32_t val = (int32_t)(in[i] * 0x8000);
out[i] = (val > 0x7FFF) ? 0x7FFF :
(val < -0x8000 ? -0x8000 : (int16_t)val);
}
}
#endif

#ifndef RARCH_INTERNAL
Expand Down Expand Up @@ -431,6 +268,6 @@ void audio_convert_init_simd(void)
audio_convert_s16_to_float_arm = (cpu & RETRO_SIMD_NEON) ?
audio_convert_s16_to_float_neon : audio_convert_s16_to_float_C;
audio_convert_float_to_s16_arm = (cpu & RETRO_SIMD_NEON) ?
audio_convert_float_to_s16_neon : audio_convert_float_to_s16_C;
convert_float_to_s16_neon : convert_float_to_s16_C;
#endif
}
64 changes: 0 additions & 64 deletions audio/audio_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ extern "C" {

#if defined(__SSE2__)
#define audio_convert_s16_to_float audio_convert_s16_to_float_SSE2
#define audio_convert_float_to_s16 audio_convert_float_to_s16_SSE2

/**
* audio_convert_s16_to_float_SSE2:
Expand All @@ -46,23 +45,8 @@ extern "C" {
void audio_convert_s16_to_float_SSE2(float *out,
const int16_t *in, size_t samples, float gain);

/**
* audio_convert_float_to_s16_SSE2:
* @out : output buffer
* @in : input buffer
* @samples : size of samples to be converted
*
* Converts audio samples from floating point
* to signed integer 16-bit.
*
* SSE2 implementation callback function.
**/
void audio_convert_float_to_s16_SSE2(int16_t *out,
const float *in, size_t samples);

#elif defined(__ALTIVEC__)
#define audio_convert_s16_to_float audio_convert_s16_to_float_altivec
#define audio_convert_float_to_s16 audio_convert_float_to_s16_altivec

/**
* audio_convert_s16_to_float_altivec:
Expand All @@ -79,33 +63,14 @@ void audio_convert_float_to_s16_SSE2(int16_t *out,
void audio_convert_s16_to_float_altivec(float *out,
const int16_t *in, size_t samples, float gain);

/**
* audio_convert_float_to_s16_altivec:
* @out : output buffer
* @in : input buffer
* @samples : size of samples to be converted
*
* Converts audio samples from floating point
* to signed integer 16-bit.
*
* AltiVec implementation callback function.
**/
void audio_convert_float_to_s16_altivec(int16_t *out,
const float *in, size_t samples);

#elif defined(__ARM_NEON__) && !defined(VITA)
#define audio_convert_s16_to_float audio_convert_s16_to_float_arm
#define audio_convert_float_to_s16 audio_convert_float_to_s16_arm

void (*audio_convert_s16_to_float_arm)(float *out,
const int16_t *in, size_t samples, float gain);

void (*audio_convert_float_to_s16_arm)(int16_t *out,
const float *in, size_t samples);

#elif defined(_MIPS_ARCH_ALLEGREX)
#define audio_convert_s16_to_float audio_convert_s16_to_float_ALLEGREX
#define audio_convert_float_to_s16 audio_convert_float_to_s16_ALLEGREX

/**
* audio_convert_s16_to_float_ALLEGREX:
Expand All @@ -121,23 +86,8 @@ void (*audio_convert_float_to_s16_arm)(int16_t *out,
**/
void audio_convert_s16_to_float_ALLEGREX(float *out,
const int16_t *in, size_t samples, float gain);

/**
* audio_convert_float_to_s16_ALLEGREX:
* @out : output buffer
* @in : input buffer
* @samples : size of samples to be converted
*
* Converts audio samples from floating point
* to signed integer 16-bit.
*
* MIPS ALLEGREX implementation callback function.
**/
void audio_convert_float_to_s16_ALLEGREX(int16_t *out,
const float *in, size_t samples);
#else
#define audio_convert_s16_to_float audio_convert_s16_to_float_C
#define audio_convert_float_to_s16 audio_convert_float_to_s16_C
#endif

/**
Expand All @@ -155,20 +105,6 @@ void audio_convert_float_to_s16_ALLEGREX(int16_t *out,
void audio_convert_s16_to_float_C(float *out,
const int16_t *in, size_t samples, float gain);

/**
* audio_convert_float_to_s16_C:
* @out : output buffer
* @in : input buffer
* @samples : size of samples to be converted
*
* Converts audio samples from floating point
* to signed integer 16-bit.
*
* C implementation callback function.
**/
void audio_convert_float_to_s16_C(int16_t *out,
const float *in, size_t samples);

/**
* audio_convert_init_simd:
*
Expand Down
Loading

0 comments on commit 2422dfb

Please sign in to comment.