forked from JailDoctor/JailAudio
- [FIX] La musica duraba la meitat per contar samples en compte de bytes
This commit is contained in:
@@ -20,6 +20,7 @@ struct JA_Channel_t {
|
|||||||
|
|
||||||
struct JA_Music_t {
|
struct JA_Music_t {
|
||||||
int samples {0};
|
int samples {0};
|
||||||
|
Uint32 length {0};
|
||||||
int pos {0};
|
int pos {0};
|
||||||
int times {0};
|
int times {0};
|
||||||
short* output {NULL};
|
short* output {NULL};
|
||||||
@@ -60,13 +61,13 @@ void audioCallback(void * userdata, uint8_t * stream, int len) {
|
|||||||
volume = JA_musicVolume * (1.0 - percent);
|
volume = JA_musicVolume * (1.0 - percent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const int size = SDL_min(len, (current_music->samples-current_music->pos)*2);
|
const int size = SDL_min(len, current_music->length - current_music->pos);
|
||||||
SDL_MixAudioFormat(stream, (Uint8*)(current_music->output+current_music->pos), AUDIO_S16, size, volume);
|
SDL_MixAudioFormat(stream, (Uint8*)(current_music->output)+current_music->pos, AUDIO_S16, size, volume);
|
||||||
current_music->pos += size/2;
|
current_music->pos += size;
|
||||||
if (size < len) {
|
if (size < len) {
|
||||||
if (current_music->times != 0) {
|
if (current_music->times != 0) {
|
||||||
SDL_MixAudioFormat(stream+size, (Uint8*)current_music->output, AUDIO_S16, len-size, volume);
|
SDL_MixAudioFormat(stream+size, (Uint8*)current_music->output, AUDIO_S16, len-size, volume);
|
||||||
current_music->pos = (len-size)/2;
|
current_music->pos = len-size;
|
||||||
if (current_music->times > 0) current_music->times--;
|
if (current_music->times > 0) current_music->times--;
|
||||||
} else {
|
} else {
|
||||||
current_music->pos = 0;
|
current_music->pos = 0;
|
||||||
@@ -136,6 +137,7 @@ JA_Music_t *JA_LoadMusic(Uint8* buffer, Uint32 length)
|
|||||||
SDL_Log("Music length: %f\n", float(music->samples)/float(JA_freq));
|
SDL_Log("Music length: %f\n", float(music->samples)/float(JA_freq));
|
||||||
if (cvt.needed) {
|
if (cvt.needed) {
|
||||||
cvt.len = music->samples * chan * 2;
|
cvt.len = music->samples * chan * 2;
|
||||||
|
music->length = cvt.len;
|
||||||
cvt.buf = (Uint8 *) SDL_malloc(cvt.len * cvt.len_mult);
|
cvt.buf = (Uint8 *) SDL_malloc(cvt.len * cvt.len_mult);
|
||||||
SDL_memcpy(cvt.buf, music->output, cvt.len);
|
SDL_memcpy(cvt.buf, music->output, cvt.len);
|
||||||
SDL_ConvertAudio(&cvt);
|
SDL_ConvertAudio(&cvt);
|
||||||
|
|||||||
Reference in New Issue
Block a user