mirror of
https://github.com/visualboyadvance-m/visualboyadvance-m
synced 2025-10-06 16:12:51 +02:00
Compare commits
3 Commits
install-re
...
libsample-
Author | SHA1 | Date | |
---|---|---|---|
|
d71942f7a4 | ||
|
bd734fb019 | ||
|
139aff1b50 |
@@ -18,6 +18,7 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <SDL_events.h>
|
#include <SDL_events.h>
|
||||||
|
#include <samplerate.h>
|
||||||
#include "SoundSDL.h"
|
#include "SoundSDL.h"
|
||||||
#include "../gba/Globals.h"
|
#include "../gba/Globals.h"
|
||||||
#include "../gba/Sound.h"
|
#include "../gba/Sound.h"
|
||||||
@@ -76,7 +77,7 @@ void SoundSDL::read(uint16_t* stream, int length) {
|
|||||||
SDL_SemPost(data_read);
|
SDL_SemPost(data_read);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundSDL::write(uint16_t * finalWave, int length) {
|
void SoundSDL::write(uint16_t* finalWave, int length) {
|
||||||
if (!initialized)
|
if (!initialized)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -88,6 +89,36 @@ void SoundSDL::write(uint16_t * finalWave, int length) {
|
|||||||
std::size_t samples = length / 4;
|
std::size_t samples = length / 4;
|
||||||
std::size_t avail;
|
std::size_t avail;
|
||||||
|
|
||||||
|
// Create a new SRC_STATE object for the resampling
|
||||||
|
int error;
|
||||||
|
SRC_STATE* src_state = src_new(SRC_SINC_FASTEST, 2, &error);
|
||||||
|
if (!src_state) {
|
||||||
|
// Handle the error
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert your uint16_t* data to float*
|
||||||
|
float* finalWaveFloat = new float[length];
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
finalWaveFloat[i] = (float)finalWave[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set up the SRC_DATA struct
|
||||||
|
SRC_DATA src_data;
|
||||||
|
src_data.data_in = finalWaveFloat;
|
||||||
|
src_data.input_frames = length / 2;
|
||||||
|
src_data.data_out = finalWaveFloat;
|
||||||
|
src_data.output_frames = length / 2;
|
||||||
|
src_data.src_ratio = 1.0; // since desired_sample_rate matches current_sample_rate
|
||||||
|
|
||||||
|
// Perform the resampling
|
||||||
|
error = src_process(src_state, &src_data);
|
||||||
|
if (error) {
|
||||||
|
// Handle the error
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
src_delete(src_state);
|
||||||
|
|
||||||
while ((avail = samples_buf.avail() / 2) < samples) {
|
while ((avail = samples_buf.avail() / 2) < samples) {
|
||||||
samples_buf.write(finalWave, avail * 2);
|
samples_buf.write(finalWave, avail * 2);
|
||||||
|
|
||||||
@@ -110,8 +141,10 @@ void SoundSDL::write(uint16_t * finalWave, int length) {
|
|||||||
samples_buf.write(finalWave, samples * 2);
|
samples_buf.write(finalWave, samples * 2);
|
||||||
|
|
||||||
SDL_UnlockMutex(mutex);
|
SDL_UnlockMutex(mutex);
|
||||||
}
|
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
delete[] finalWaveFloat;
|
||||||
|
}
|
||||||
|
|
||||||
bool SoundSDL::init(long sampleRate) {
|
bool SoundSDL::init(long sampleRate) {
|
||||||
if (initialized) deinit();
|
if (initialized) deinit();
|
||||||
|
Reference in New Issue
Block a user