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

Anthony Walter sysrpl at gmail.com
Tue May 7 17:49:29 CEST 2019


In my current thread on the subject of "Next tutoring project" I believe
I've nailed down my idea.  The project will be a node based sound and
effect generation program where students can create functions that either
create tones or effects.

I also want to add the ability to apply effects to sound files, in to
generated tones, and from my previous experience with sound files I wanted
to ask for some help from you the community to add this specific feature
into the new music project for teaching kids how to program.

What I need is the following:

A function to take an mp3 stream and given a time and a duration to convert
the mp3 data into left and right audio samples of a specific samples per
second and sample type.

So for example, if I load an entire mp3 into a memory stream it might be
called:

var
  MusicFile: TMemoryStream;

..
  MusicFile := TMemoryStream.Create;
  MusicFile.LoadFromStream('my_music.mp3');
  WriteLn('The music file is ', Mp3StreamDuration(MusicFile), ' long in
seconds');

I would need these functions:

{ Return the duration of the music or sounds in an Mp3 stream in seconds }
function Mp3StreamDuration(Stream: TStream): Single;

{ Mp3StreamSamples outputs left and right audio samples from an mp3 stream
given a Start,
  Duration, SamplesPerSecond, and buffer information. Buffer count will be
= Duration *
  SamplesPerSecond rounded up to the nearest whole value }

type
  TSoundSample = record
    Left: SmallInt;
    Right: SmallInt;
  end;
  PSoundSample = ^TSoundSample;

procedure Mp3StreamSamples(Stream: TStream; Start, Duration: Single;
SamplesPerSecond: Integer; Buffer: PSoundSample; BufferCount: Integer);

If these functions could be repeated for the wav file format or other
formats (ogg and such) that would be much appreciate.

By the way, the mp3 format is now free of any licensing restrictions.

If anyone has any questions or would like to help let me know. I can
provide you with a test application to output the sound into the platform
independent audio system if you need it for testing.

Thanks again everyone.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20190507/1a992aef/attachment.html>


More information about the lazarus mailing list