Merge pull request #728 from pcercuei/libretro-wiiu-v4
[pcsx_rearmed.git] / deps / libretro-common / include / audio / audio_mix.h
CommitLineData
3719602c
PC
1/* Copyright (C) 2010-2020 The RetroArch team
2 *
3 * ---------------------------------------------------------------------------------------
4 * The following license statement only applies to this file (audio_mix.h).
5 * ---------------------------------------------------------------------------------------
6 *
7 * Permission is hereby granted, free of charge,
8 * to any person obtaining a copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
11 * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 */
22
23#ifndef __LIBRETRO_SDK_AUDIO_MIX_H__
24#define __LIBRETRO_SDK_AUDIO_MIX_H__
25
26#include <retro_common_api.h>
27
28#include <stdint.h>
29#include <stddef.h>
30#ifdef _WIN32
31#include <direct.h>
32#else
33#include <unistd.h>
34#endif
35
36#include <formats/rwav.h>
37#include <audio/audio_resampler.h>
38
39RETRO_BEGIN_DECLS
40
41typedef struct
42{
43 double ratio;
44 void *buf;
45 int16_t *upsample_buf;
46 float *float_buf;
47 float *float_resample_buf;
48 int16_t *resample_buf;
49 const retro_resampler_t *resampler;
50 void *resampler_data;
51 rwav_t *rwav;
52 ssize_t len;
53 size_t resample_len;
54 int sample_rate;
55 bool resample;
56} audio_chunk_t;
57
58#if defined(__SSE2__)
59#define audio_mix_volume audio_mix_volume_SSE2
60
61void audio_mix_volume_SSE2(float *out,
62 const float *in, float vol, size_t samples);
63#else
64#define audio_mix_volume audio_mix_volume_C
65#endif
66
67void audio_mix_volume_C(float *dst, const float *src, float vol, size_t samples);
68
69void audio_mix_free_chunk(audio_chunk_t *chunk);
70
71audio_chunk_t* audio_mix_load_wav_file(const char *path, int sample_rate,
72 const char *resampler_ident, enum resampler_quality quality);
73
74size_t audio_mix_get_chunk_num_samples(audio_chunk_t *chunk);
75
76/**
77 * audio_mix_get_chunk_sample:
78 * @chunk : audio chunk instance
79 * @channel : channel of the sample (0=left, 1=right)
80 * @index : index of the sample
81 *
82 * Get a sample from an audio chunk.
83 *
84 * Returns: A signed 16-bit audio sample, (if necessary) resampled into the desired output rate.
85 **/
86int16_t audio_mix_get_chunk_sample(audio_chunk_t *chunk, unsigned channel, size_t sample);
87
88int16_t* audio_mix_get_chunk_samples(audio_chunk_t *chunk);
89
90int audio_mix_get_chunk_num_channels(audio_chunk_t *chunk);
91
92RETRO_END_DECLS
93
94#endif