diff options
author | Nadia Holmquist Pedersen <nadia@nhp.sh> | 2020-06-03 13:54:28 +0200 |
---|---|---|
committer | Nadia Holmquist Pedersen <nadia@nhp.sh> | 2020-06-03 13:54:28 +0200 |
commit | f9f366e296a68be0aa2eb7bfd0552da31896a18c (patch) | |
tree | f52760d5505b84074a9c1b50b4fe16e40035ba06 /src/frontend/Util_Audio.cpp | |
parent | b746c0b7279d1f5b4bcfd02c115b09d583e9df4f (diff) | |
parent | d6332f96f162849ad0dde2738cacd3fae6e76e5d (diff) |
Merge remote-tracking branch 'remotes/upstream/master' into feature/qt-platform
# Conflicts:
# src/frontend/qt_sdl/CMakeLists.txt
# src/frontend/qt_sdl/Platform.cpp
# src/frontend/qt_sdl/main.cpp
Diffstat (limited to 'src/frontend/Util_Audio.cpp')
-rw-r--r-- | src/frontend/Util_Audio.cpp | 72 |
1 files changed, 65 insertions, 7 deletions
diff --git a/src/frontend/Util_Audio.cpp b/src/frontend/Util_Audio.cpp index fe0ecab..fc80c90 100644 --- a/src/frontend/Util_Audio.cpp +++ b/src/frontend/Util_Audio.cpp @@ -17,16 +17,15 @@ */ #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <math.h> #include "FrontendUtil.h" -#include "Config.h" -#include "qt_sdl/PlatformConfig.h" // FIXME!!! -#include "Platform.h" #include "NDS.h" -#include "GBACart.h" + +#include "mic_blow.h" namespace Frontend @@ -35,13 +34,22 @@ namespace Frontend int AudioOut_Freq; float AudioOut_SampleFrac; +s16* MicBuffer; +u32 MicBufferLength; +u32 MicBufferReadPos; + void Init_Audio(int outputfreq) { AudioOut_Freq = outputfreq; AudioOut_SampleFrac = 0; + + MicBuffer = nullptr; + MicBufferLength = 0; + MicBufferReadPos = 0; } + int AudioOut_GetNumSamples(int outlen) { float f_len_in = (outlen * 32823.6328125) / (float)AudioOut_Freq; @@ -52,14 +60,12 @@ int AudioOut_GetNumSamples(int outlen) return len_in; } -void AudioOut_Resample(s16* inbuf, int inlen, s16* outbuf, int outlen) +void AudioOut_Resample(s16* inbuf, int inlen, s16* outbuf, int outlen, int volume) { float res_incr = inlen / (float)outlen; float res_timer = 0; int res_pos = 0; - int volume = Config::AudioVolume; - for (int i = 0; i < outlen; i++) { outbuf[i*2 ] = (inbuf[res_pos*2 ] * volume) >> 8; @@ -74,4 +80,56 @@ void AudioOut_Resample(s16* inbuf, int inlen, s16* outbuf, int outlen) } } + +void Mic_FeedSilence() +{ + MicBufferReadPos = 0; + NDS::MicInputFrame(NULL, 0); +} + +void Mic_FeedNoise() +{ + int sample_len = sizeof(mic_blow) / sizeof(u16); + static int sample_pos = 0; + + s16 tmp[735]; + + for (int i = 0; i < 735; i++) + { + tmp[i] = mic_blow[sample_pos]; + sample_pos++; + if (sample_pos >= sample_len) sample_pos = 0; + } + + NDS::MicInputFrame(tmp, 735); +} + +void Mic_FeedExternalBuffer() +{ + if (!MicBuffer) return Mic_FeedSilence(); + + if ((MicBufferReadPos + 735) > MicBufferLength) + { + s16 tmp[735]; + u32 len1 = MicBufferLength - MicBufferReadPos; + memcpy(&tmp[0], &MicBuffer[MicBufferReadPos], len1*sizeof(s16)); + memcpy(&tmp[len1], &MicBuffer[0], (735 - len1)*sizeof(s16)); + + NDS::MicInputFrame(tmp, 735); + MicBufferReadPos = 735 - len1; + } + else + { + NDS::MicInputFrame(&MicBuffer[MicBufferReadPos], 735); + MicBufferReadPos += 735; + } +} + +void Mic_SetExternalBuffer(s16* buffer, u32 len) +{ + MicBuffer = buffer; + MicBufferLength = len; + MicBufferReadPos = 0; +} + } |