08-24-2025, 12:07 PM
(This post was last modified: 08-24-2025, 12:09 PM by a740g.
Edit Reason: Fix typo
)
For short sounds, you can use _SNDNEW, _MEMSOUND, and _MEMPUT. _SNDNEW can automatically handle sample format conversion and even sample rate conversion in QB64-PE v4.2.0 and above.
A "frame" is a set of samples, one for each channel, that together describe a single point in time in the audio stream. So, for stereo audio, each frame has two samples: one for the left channel and one for the right.
For example, if your audio data is 16-bit stereo and 1024 bytes in size, then:
frames = (size / channels) / bytes_per_sample
= (1024 / 2) / 2
= 256 frames
Simply calculate "fames" based on the above and pass that and the other arguments based on the audio data. You do not need to perform any sample format or rate conversion. _SNDNEW does that automagically for you - just a simple data copy using _MEMSOUND and _MEMPUT will do.
Note that _SNDNEW may not be ideal for playing long streaming audio, such as from the internet or large files on disk. In those cases, I recommend using _SNDRAW or _SNDRAWBATCH.
You'll need to implement both a sample format converter and a sample rate converter. To keep things simple, start with a basic sample rate converter and perform format conversion during that step. Once you have the converted samples, you can feed them directly into _SNDRAW or _SNDRAWBATCH.
Personally, I prefer _SNDRAWBATCH since it lets me process and dispatch small chunks of audio data at a time, which helps improve performance.
A "frame" is a set of samples, one for each channel, that together describe a single point in time in the audio stream. So, for stereo audio, each frame has two samples: one for the left channel and one for the right.
For example, if your audio data is 16-bit stereo and 1024 bytes in size, then:
frames = (size / channels) / bytes_per_sample
= (1024 / 2) / 2
= 256 frames
Simply calculate "fames" based on the above and pass that and the other arguments based on the audio data. You do not need to perform any sample format or rate conversion. _SNDNEW does that automagically for you - just a simple data copy using _MEMSOUND and _MEMPUT will do.
Note that _SNDNEW may not be ideal for playing long streaming audio, such as from the internet or large files on disk. In those cases, I recommend using _SNDRAW or _SNDRAWBATCH.
You'll need to implement both a sample format converter and a sample rate converter. To keep things simple, start with a basic sample rate converter and perform format conversion during that step. Once you have the converted samples, you can feed them directly into _SNDRAW or _SNDRAWBATCH.
Personally, I prefer _SNDRAWBATCH since it lets me process and dispatch small chunks of audio data at a time, which helps improve performance.

