| 1 | /* Copyright (C) 2010-2020 The RetroArch team |
| 2 | * |
| 3 | * --------------------------------------------------------------------------------------- |
| 4 | * The following license statement only applies to this file (audio_mixer.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_MIXER__H |
| 24 | #define __LIBRETRO_SDK_AUDIO_MIXER__H |
| 25 | |
| 26 | #include <stdint.h> |
| 27 | #include <stddef.h> |
| 28 | #include <stdlib.h> |
| 29 | |
| 30 | #ifdef HAVE_CONFIG_H |
| 31 | #include "config.h" |
| 32 | #endif |
| 33 | |
| 34 | #include <boolean.h> |
| 35 | #include <retro_common_api.h> |
| 36 | |
| 37 | #include <audio/audio_resampler.h> |
| 38 | |
| 39 | RETRO_BEGIN_DECLS |
| 40 | |
| 41 | enum audio_mixer_type |
| 42 | { |
| 43 | AUDIO_MIXER_TYPE_NONE = 0, |
| 44 | AUDIO_MIXER_TYPE_WAV, |
| 45 | AUDIO_MIXER_TYPE_OGG, |
| 46 | AUDIO_MIXER_TYPE_MOD, |
| 47 | AUDIO_MIXER_TYPE_FLAC, |
| 48 | AUDIO_MIXER_TYPE_MP3 |
| 49 | }; |
| 50 | |
| 51 | typedef struct audio_mixer_sound audio_mixer_sound_t; |
| 52 | typedef struct audio_mixer_voice audio_mixer_voice_t; |
| 53 | |
| 54 | typedef void (*audio_mixer_stop_cb_t)(audio_mixer_sound_t* sound, unsigned reason); |
| 55 | |
| 56 | /* Reasons passed to the stop callback. */ |
| 57 | #define AUDIO_MIXER_SOUND_FINISHED 0 |
| 58 | #define AUDIO_MIXER_SOUND_STOPPED 1 |
| 59 | #define AUDIO_MIXER_SOUND_REPEATED 2 |
| 60 | |
| 61 | void audio_mixer_init(unsigned rate); |
| 62 | |
| 63 | void audio_mixer_done(void); |
| 64 | |
| 65 | audio_mixer_sound_t* audio_mixer_load_wav(void *buffer, int32_t size, |
| 66 | const char *resampler_ident, enum resampler_quality quality); |
| 67 | audio_mixer_sound_t* audio_mixer_load_ogg(void *buffer, int32_t size); |
| 68 | audio_mixer_sound_t* audio_mixer_load_mod(void *buffer, int32_t size); |
| 69 | audio_mixer_sound_t* audio_mixer_load_flac(void *buffer, int32_t size); |
| 70 | audio_mixer_sound_t* audio_mixer_load_mp3(void *buffer, int32_t size); |
| 71 | |
| 72 | void audio_mixer_destroy(audio_mixer_sound_t* sound); |
| 73 | |
| 74 | audio_mixer_voice_t* audio_mixer_play(audio_mixer_sound_t* sound, |
| 75 | bool repeat, float volume, |
| 76 | const char *resampler_ident, |
| 77 | enum resampler_quality quality, |
| 78 | audio_mixer_stop_cb_t stop_cb); |
| 79 | |
| 80 | void audio_mixer_stop(audio_mixer_voice_t* voice); |
| 81 | |
| 82 | float audio_mixer_voice_get_volume(audio_mixer_voice_t *voice); |
| 83 | |
| 84 | void audio_mixer_voice_set_volume(audio_mixer_voice_t *voice, float val); |
| 85 | |
| 86 | void audio_mixer_mix(float* buffer, size_t num_frames, float volume_override, bool override); |
| 87 | |
| 88 | RETRO_END_DECLS |
| 89 | |
| 90 | #endif |