emscripten-core / emscripten-core/emscripten

I can hear small noises when I use alSourceQueueBuffers() of openal.

Open
#11,380 6 comments 1 reaction 0 assignees View on GitHub
wontfix
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

The following code reproduces the problem I described, but you have to listen very carefully to hear the noise.
I played music for ten seconds, and the noise came out nine times.
```c++
#include
#include
#include
#include
#include

int main() {
// open device
ALCdevice* device = alcOpenDevice(NULL);
ALCcontext* context = alcCreateContext(device, NULL);
alcMakeContextCurrent(context);

ALuint buffers[10];
alGenBuffers(10, buffers);
ALuint sources[1];
alGenSources(1, sources);

// file_example_WAV_10MG.wav is donwload at here:
// https://file-examples.com/index.php/sample-audio-files/sample-wav-download/
FILE* file_wav = fopen("file_example_WAV_10MG.wav", "rb");
fseek(file_wav, 0, SEEK_END);
int file_size = ftell(file_wav);
fseek(file_wav, 0, SEEK_SET);
unsigned char* file_buffer = (unsigned char*) malloc(file_size);
fread(file_buffer, file_size, 1, file_wav);
int offset = 44;

int size = 176400; //176400 = 44100 * 2(channals) * 2(ALshort)
ALshort music[10][88200];
memcpy(&music, &file_buffer[offset], size*10);

for (int i = 0 ; i < 10 ; i++)
{
alBufferData(buffers[i], AL_FORMAT_STEREO16, music[i], size, 44100);
alSourceQueueBuffers(sources[0], 1, &buffers[i]);
}

alSourcePlay(sources[0]);

emscripten_sleep(1000000);

// close device
context = alcGetCurrentContext();
device = alcGetContextsDevice(context);
alcMakeContextCurrent(NULL);
alcDestroyContext(context);
alcCloseDevice(device);

return 0;
}
```
Compile Command:
em++ openal.cc -o openal.html -s ALLOW_MEMORY_GROWTH=1 -s EXIT_RUNTIME=1 --preload-file ./file_example_WAV_10MG.wav

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.