Recent

Author Topic: Audio for Lazarus  (Read 32619 times)

Fred vS

  • Hero Member
  • *****
  • Posts: 3158
    • StrumPract is the musicians best friend
Audio for Lazarus
« on: December 20, 2012, 08:48:59 pm »
Hello everybody.  :D
Im very happy to open that new topic.
Everything about Audio and Lazarus is welcome.

Here is some explanations about the wav format :
http://www.sonicspot.com/guide/wavefiles.html

I try to understand how stereo works :

Quote
Multi-channel digital audio samples are stored as interlaced wave data which simply means that the audio samples of a multi-channel (such as stereo and surround) wave file are stored by cycling through the audio samples for each channel before advancing to the next sample time. This is done so that the audio files can be played or streamed before the entire file can be read. This is handy when playing a large file from disk (that may not completely fit into memory) or streaming a file over the Internet. The values in the diagram below would be stored in a Wave file in the order they are listed in the Value column (top to bottom).

Time Channel    Value
0      1 (left)     0x0053
        2 (right)   0x0024
1      1 (left)     0x0057
        2 (right)   0x0029
2      1 (left)     0x0063
        2 (right)   0x003C

Interlaced Stereo Wave Samples

One point about sample data that may cause some confusion is that when samples are represented with 8-bits, they are specified as unsigned values. All other sample bit-sizes are specified as signed values. For example a 16-bit sample can range from -32,768 to +32,767 with a mid-point (silence) at 0.

First question, in Pascal we use a array of int16 to store the audio data. If i have well understood, if the wav is stereo, array[odd] is left channel and array[even] is right channel ?

This is the first question and all others questions and answers about Audio for Lazarus are welcome. ;)
« Last Edit: December 20, 2012, 08:58:25 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Audio for Lazarus
« Reply #1 on: December 20, 2012, 09:39:33 pm »
@ First question, in Pascal we use a array of int16 to store the audio data. If i have well understood, if the wav is stereo, array[odd] is left channel and array[even] is right channel ?

Yes. Instead of array, you can also use a piece of memory allocated via getmem/freemem.

The name of 16-bit signed is SmallInt.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Fred vS

  • Hero Member
  • *****
  • Posts: 3158
    • StrumPract is the musicians best friend
Re: Audio for Lazarus
« Reply #2 on: December 20, 2012, 09:50:13 pm »
@ Blaazen : + 10 : Total : 10 points.

Super Blaazen, so happy to know there are other pasacal-audio fans.

Quote
Yes. Instead of array, you can also use a piece of memory allocated via getmem/freemem.

Is it better ?   :-[
« Last Edit: December 20, 2012, 09:55:14 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Audio for Lazarus
« Reply #3 on: December 20, 2012, 10:49:07 pm »
Not better. I mean that you will probably need to send data to some external audio library. And then it depends what data format the library expects.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Fred vS

  • Hero Member
  • *****
  • Posts: 3158
    • StrumPract is the musicians best friend
Re: Audio for Lazarus
« Reply #4 on: December 20, 2012, 10:52:36 pm »
@ Blaazen : OK.

Second quiz : (if you see error in my explanation, please advise).

I want to understand how the wav data (and it seems also the buffers data) are stored.

The song is a huge array of integers where X is the position in the sound.

That array of integers could be array of 8bits or more (it is called resolution).

Each position (X) is called a Sample and represents a certain amount of time.

And here i have doubt about the range of value, is it that the resolution or the range of array ?

In pascal that array could be : Buffer: array[0..$ffff] of cInt16; 

Let say Y is $ffff and Z is length(cInt16).

A value referencing a certain frequency is stored from 0 to Y.

Quote
Time Channel    Value     ( from 0 to Z)
0      1 (left)     0x0053  ///// highest left frequency (from 0 to Z)
        2 (right)   0x0024  ///// highest right frequency (from 0 to Z)
1      1 (left)     0x0057
        2 (right)   0x0029
2      1 (left)     0x0063
        2 (right)   0x003C

...

Y-1   1 (left)     0x0053 ///// lowest left frequency (from 0 to Z)
Y     2 (right)   0x003C  ///// lowest right frequency (from 0 to Z)

Is that shema right ?
« Last Edit: December 20, 2012, 10:55:13 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

aguiar

  • New Member
  • *
  • Posts: 47
  • Ubuntu 14.04
Re: Audio for Lazarus
« Reply #5 on: December 20, 2012, 10:55:15 pm »

Fred vS

  • Hero Member
  • *****
  • Posts: 3158
    • StrumPract is the musicians best friend
Re: Audio for Lazarus
« Reply #6 on: December 20, 2012, 11:09:52 pm »
@ aguiar : thanks but ACS do not help me to deeply understand how audio works (and i never was able to use it with OSX or Linux).

So the suspense is still there : is the schema of earlier topic right ?  :-X
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Audio for Lazarus
« Reply #7 on: December 20, 2012, 11:11:21 pm »
as far as I understand wav does not support multiple channels in a single array of data you need one array for each channel. the size of cint16 is what is called the bitness of the sample aka the how detailed is the sampling method for each sample taken, where sample is one position in the array. Now depending on the sampling rate which you have to know in advance you can calculate how many positions are used per second eg a 44.1Khz sampling rate means that in 1 sec you have to play 44100 items from the array
again for multiple channels you either need multiple arrays some libraries might concatenate those in to one but it would normaly be one after an other but will not multiplex them in the way you wrote above.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Fred vS

  • Hero Member
  • *****
  • Posts: 3158
    • StrumPract is the musicians best friend
Re: Audio for Lazarus
« Reply #8 on: December 20, 2012, 11:17:52 pm »
Quote
again for multiple channels you either need multiple arrays some libraries might concatenate those in to one but it would normaly be one after an other but will not multiplex them in the way you wrote above.

To clarify things, i use SndFile library who does all the work and mix both array into one.
But SndFile gives me a filled buffer (a array) and let me do what i want with it. OK, but what is inside that buffer, it is what i want to understand.

So the suspense is still there : is that earlier schema right ? (Reply #4 on: Today at 10:52:36)
« Last Edit: December 20, 2012, 11:19:58 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Audio for Lazarus
« Reply #9 on: December 20, 2012, 11:23:51 pm »
@ aguiar : thanks but ACS do not help me to deeply understand how audio works (and i never was able to use it with OSX or Linux).

I have the same experience. ~3 or 4 years back I was able to compile it in Windows 32-bit but I was never successful on 64-bit Linux. ACS is maybe discontinued.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Audio for Lazarus
« Reply #10 on: December 20, 2012, 11:39:43 pm »
I thought I was clear but after reading my answer it seems I was too much in my head to give a definet answer sorry about that. Let me say that I have never coded any sound playing routines I'm more than huppy to use the existing libraries to do the job for me but from what I understand about wav format and the description of the sndfile libraries api I assume that the format that is returned is in the form of

Z:= length(array);
ChanelSize := Z / chanelcount;
channel0Range := 0..Channelsize -1;
Chanel1Range := ChanelSize..(ChanelSize*2) -1
ChannelNRange := (ChanelSize*(N-1))..(ChanelSize*N)-1;

PS
That is for the wav format only, other formats that support frames might have different schema eg each frame has all channels required for it in the above schema. So you have some tests to write I guess. Sorry I can't be of more help.
« Last Edit: December 20, 2012, 11:45:32 pm by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Fred vS

  • Hero Member
  • *****
  • Posts: 3158
    • StrumPract is the musicians best friend
Re: Audio for Lazarus
« Reply #11 on: December 20, 2012, 11:43:52 pm »
Quote
ACS is maybe discontinued.
Afaik, yes, ACS is dead.

But if you see the huge number of systems SndFile covers :

Quote
    Every platform supported by Debian GNU/Linux including x86_64-linux-gnu, i486-linux-gnu, powerpc-linux-gnu, sparc-linux-gnu, alpha-linux-gnu, mips-linux-gnu and armel-linux-gnu.
    arm-linux-androideab (Android phones OS)
    powerpc-apple-darwin7.0 (Mac OS X 10.3)
    sparc-sun-solaris2.8 (using gcc)
    mips-sgi-irix5.3 (using gcc)
    QNX 6.0
    i386-unknown-openbsd2.9

At the moment, each new release is being tested on i386 Linux, x86_64 Linux, PowerPC Linux, Win32 and Win64.

 :o

So the suspense is still there : is that earlier schema right ? (Reply #4 on: Today at 10:52:36)  :-[
« Last Edit: December 21, 2012, 12:11:01 am by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Fred vS

  • Hero Member
  • *****
  • Posts: 3158
    • StrumPract is the musicians best friend
Re: Audio for Lazarus
« Reply #12 on: December 21, 2012, 02:06:06 pm »
@ Blaazen :

Quote
The name of 16-bit signed is SmallInt.

In my (old) school book it is written : SmallInt : Signed: From −32,768 to 32,767.

So i do not understand. 0 is silence (ok ?) and -1 (or less) is what ? hypra-silence ?  %)

PS : So the suspense is still there : is that earlier schema right ? (schema of Reply #4 of December 20, 2012, 10:52:36 pm)  :-[


« Last Edit: December 21, 2012, 02:13:06 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Dibo

  • Hero Member
  • *****
  • Posts: 1048
Re: Audio for Lazarus
« Reply #13 on: December 21, 2012, 03:17:35 pm »
Anyone know which audio library need least external libs? I have tested SDL, Omega, etc but each have some dependencies like mpg123, openal, and other libs. What I found that Bass is perfect but not for commercial projects :/

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Audio for Lazarus
« Reply #14 on: December 21, 2012, 04:47:18 pm »
Sound is vibration. The amplitude changes around zero. If changes are between <-1, 1> it will be a very silent sound. Changes <-32768, 32767> are loud.
Constantly at 0 is a silence. But constantly at -32768 or at 32767 will be also silence. But it is not very good, IMO it is bad because later you have amplifier and speakers (it causes bias).
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

 

TinyPortal © 2005-2018