Recent

Author Topic: [SOLVED] Operation with array of bytes  (Read 12332 times)

Fred vS

  • Hero Member
  • *****
  • Posts: 3942
    • StrumPract is the musicians best friend
[SOLVED] Operation with array of bytes
« on: November 15, 2012, 09:29:47 pm »
Hello everybody.

I have a filled array of bytes and want to do a division for each byte of the array.

This array contains the buffer of a audio-file. (the goal is to change volume before to give the buffer to a other process)

Code: [Select]
var

outbuf : array [0..2047]  of byte  ; 


////// the array is filled with datas...

procedure change_volume_array() ; //// here i want to ajust volume div 2
var x
begin
  x := 0 ;
   while x <  Length(outbuf) )   do begin

outbuf[x]  := round(outbuf[x] * 0.5 );

   inc(x) ;
  end;   
end;


Sadly, i do not have the result i want, i get only strange noise.

Other strange thing, if i do :

Code: [Select]
procedure change_volume_To_0() ; //// here i want to ajust volume to 0
var x
begin
  x := 0 ;
   while x <  Length(outbuf) )   do begin

outbuf[x]  := 0;

   inc(x) ;
  end;   
end;

I attempted to ear nothing but in fact i still ear noise (garbage).

Is it a problem of translation Integer to Bytes ?

If well, what must i do ?

Thanks

« Last Edit: November 16, 2012, 02:51:49 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: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Operation with array of bytes
« Reply #1 on: November 15, 2012, 09:41:14 pm »
Your code works well here. Are you sure that input data are correct ?
You can make some output to see what is realy there:
Code: [Select]
var x: Integer;
begin
  while x <  Length(outbuf)    do begin

      writeln(inttostr(outbuf[x]));

      inc(x) ;
    end;       
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: 3942
    • StrumPract is the musicians best friend
Re: Operation with array of bytes
« Reply #2 on: November 15, 2012, 09:49:17 pm »
@ Blaazen : Thanks to answer  ;D

Sound library MPG123 gives the procedure stream.volume, so it is very easy to change the volume of  a stream.

But library SndFile does not  :'(

I have googeling to find a soiution how to change the volume in SndFile : NOTHING (even not a tip).

So i was thinking to use the procedure of first topic, but i get only garbaged sound.

Quote
Are you sure that input data are correct ?

Yes, because if i do not change the volume, it is perfect (but at volume 1). :-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

greatUnknown

  • New Member
  • *
  • Posts: 19
Re: Operation with array of bytes
« Reply #3 on: November 15, 2012, 10:05:19 pm »
Are you sure that the only thing in the buffer is volume data.  It sounds like there is
other information there also, which is getting trashed by the division.
Of course, with no mathematical operations, the sound would play normally.

Also, why would you use round (data * 0.5) when you can use data div 2?

Fred vS

  • Hero Member
  • *****
  • Posts: 3942
    • StrumPract is the musicians best friend
Re: Operation with array of bytes
« Reply #4 on: November 15, 2012, 10:10:55 pm »
Quote
Are you sure that the only thing in the buffer is volume data.

Im absolutely not sure. If somebody could give me light about that, i would be very lucky  :-[

Quote
Also, why would you use round (data * 0.5) when you can use data div 2?
Coz its easier to change into Trunc inside code  8-)
and coz 0.5 is a example, i use a variable who can be > 1  8-)


« Last Edit: November 15, 2012, 10:25:02 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: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Operation with array of bytes
« Reply #5 on: November 15, 2012, 11:02:59 pm »
So what are the data that you send to array? Is it some *.wav file?
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: 3942
    • StrumPract is the musicians best friend
Re: Operation with array of bytes
« Reply #6 on: November 15, 2012, 11:15:16 pm »
I have try with some ogg file, but not try yet with common wav.
Gonna try  :-X

[edit] Same garbage with wav files  :'(
« Last Edit: November 15, 2012, 11:18:53 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: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Operation with array of bytes
« Reply #7 on: November 15, 2012, 11:27:20 pm »
And the data are still compressed ? If yes, then it makes sense.
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: 3942
    • StrumPract is the musicians best friend
Re: Operation with array of bytes
« Reply #8 on: November 15, 2012, 11:36:12 pm »
Quote
And the data are still compressed ?

Not understood, i was thinking that wav files where not compressed ?
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: 3942
    • StrumPract is the musicians best friend
Re: Operation with array of bytes
« Reply #9 on: November 15, 2012, 11:47:46 pm »
If i add 2 arrays together, like here, no problem, the 2 streams are perfectly mixed ...

Code: [Select]
var

outbuf, outbuf2: array [0..2047]  of byte  ; 


////// the 2 arrays are filled with datas...

procedure mix_array() ; //// here i want to mix 2 arrays
var x
begin
  x := 0 ;
   while x <  Length(outbuf) )   do begin

outbuf[x]  := outbuf[x] + oufbuf2[x] ;

   inc(x) ;
  end;   
end;

But to change volume, it is other story...
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

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Operation with array of bytes
« Reply #10 on: November 15, 2012, 11:50:12 pm »
I think the question is, are you decompressing the audio data after you read it from file? What library/code are you using for OGG?

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Operation with array of bytes
« Reply #11 on: November 15, 2012, 11:53:03 pm »
Ah, you edited your post. However, all these files have some header and of course you cannot modify it. Only data can be modified.
For example, here is some minimal description of wav files: http://dracoater.blogspot.cz/2008/11/comparing-2-audio-wav-files.html
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: 3942
    • StrumPract is the musicians best friend
Re: Operation with array of bytes
« Reply #12 on: November 16, 2012, 12:05:24 am »
Quote
code are you using for OGG

I use PortAudio, together with SndFile and Mpg123...

Quote
Ah, you edited your post. However, all these files have some header and of course you cannot modify it. Only data can be modified.

Do you think that it is not possible to change then the volume or apply some DSP effect ?

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: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Operation with array of bytes
« Reply #13 on: November 16, 2012, 12:12:36 am »
Yes, it is possible but only on the data. Not to file header.
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: 3942
    • StrumPract is the musicians best friend
Re: Operation with array of bytes
« Reply #14 on: November 16, 2012, 12:17:09 am »
OK, then no solution for now,... :-[
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

 

TinyPortal © 2005-2018