[Lazarus] Soliciting help with next tutoring project, playing sounds and music

Anthony Walter sysrpl at gmail.com
Tue May 7 22:30:03 CEST 2019


Jose,

Thank you for the suggestion. I've used both BASS and FMOD extensively in
the past. Those library are for playing sounds from files or streams using
their abstracted concepts of channels. What I am looking for is something a
bit more primitive, and that is manipulating sample sounds through a series
of functions, which is something both of those are not suitable for. That
is I need to be able to extract a section of an mp3 or wav file and convert
it to left and right audio samples (in my case a pair of SmallInt values)
at a given samples per second. Then that buffer of left and right SmallInt
values are fed to student functions as a mix, where they can an echo to a
left or right sample, pan the left or right sample, chorus the left or
right sample, and so on.

For example a student might create a simple pan effect by writing:

procedure PanEffect(var Sample: TAudioSample; Time, Level: Single);
var
  Mix: Single;
begin
  if Level < 0.5 then
  begin
    Mix := 1 - Level / 0.5;
    Sample.Left := RoundSmallInt(Sample.Left + Sample.Right * Mix);
    Mix := Level / 0.5;
    Sample.Right := RoundSmallInt(Sample.Right * Mix);
  end
  else
  begin
    Level := 1 - Level;
    Mix := 1 - Level / 0.5;
    Sample.Right := RoundSmallInt(Sample.Right + Sample.Left * Mix);
    Mix := Level / 0.5;
    Sample.Left := RoundSmallInt(Sample.Left * Mix);
   end;
  end;
end;

Several effects can be chained together to alter the samples, then mix
together all the samples from the various streams or tones being played and
feed the mixed together samples to the sound driver producing the final
sound effect.

>From the perspective of the student their are either writing Tone
procedures or Effect procedures, and from the application perspective we
are working with samples per active virtual keyboard key and mixing them
down into a single stereo buffer of left and right SmallInts which are then
dispatched to the sound driver.

In the case of mp3s or wav finds, I need a function to decode a part of a
stream into a range of samples (left and right SmallInts). I don't need a
black box library to play sounds with licensing attached and I've like to
minimize the dependency on external restrictive third party libraries. And
finally both FMOD and BASS introduce a lot of complexity if the goal is
simply to retrieve audio samples as opposed to using them for playing
streams using their abstracted design of sound channels.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20190507/9ed7631a/attachment-0001.html>


More information about the lazarus mailing list