Lazarus

Programming => Graphics and Multimedia => Graphics => Topic started by: user5 on April 06, 2014, 09:37:24 am

Title: Bitmap wavefore from .wav file
Post by: user5 on April 06, 2014, 09:37:24 am
I'm on a quest to figure out how to draw a bitmap waveform from a .wav file and I would rent my soul to do that because otherwise I'll have to capture another program's waveform graphic. Even a simple VU meter in Pascal or C would help me to make a crude but good one.

I've got the source code for the sound programs ACS and Audacity but I'm afraid that I'll have trouble loading them correctly into Lazarus. Can anyone point me into the right direction?
Title: Re: Bitmap wavefore from .wav file
Post by: karaba on April 06, 2014, 10:12:14 am
well the idea is simple, a wav, to put it simple, is a bunch of numbers on after an other, those numbers can be transformed to a percentage system and shown inside a specific area, lets say 100 pixels high, now those numbers are to be translated on the Y axis of the area while each value is one position on the X axis of the area making it the time axis.

That is the main idea of drawing a wave form, by the way in order to connect those points you use a simple lineto method which uses the last known position as the start point and the new position you provide as the end point of a line.
Title: Re: Bitmap wavefore from .wav file
Post by: BigChimp on April 06, 2014, 10:20:29 am
Even a simple VU meter in Pascal or C would help me to make a crude but good one.
Searching the forum (and wiki) for the right terms can help - searching for vumeter gave this:
http://forum.lazarus.freepascal.org/index.php/topic,17599.msg138180.html#msg138180
perhaps that lib has other demo programs/controls that can show waveforms already...
Title: Re: Bitmap wavefore from .wav file
Post by: Fred vS on April 06, 2014, 01:41:31 pm
Quote
perhaps that lib has other demo programs/controls that can show waveforms already...

Hum, not yet, but like BigChimp said, there is vu meters example in uos demo package...  ;) (and follow then the idea of karaba)
Title: Re: Bitmap wavefore from .wav file
Post by: user5 on April 06, 2014, 05:19:43 pm
Well, I found a great program called Waveform.exe and it's the Windows binary waveform generator. You enter
the name of a wave file and the name of a file to save the graphic into and it makes a graphic .png file. It also accepts flac files. If the amplitude of the wave file is low then the sound spikes in the .png file will be very small but simply raising the volume of the wave file and then running it through Waveform
again solves the problem. If anyone is interested, Waveform can be found at:

http://www.hydrogenaudio.org/forums/index.php?showtopic=100036

Look for message posts #5 and #7 near the bottom of the page. Thanks for your responses! It's a very nice program.
Title: Re: Bitmap wavefore from .wav file
Post by: user5 on April 07, 2014, 12:49:44 am
I just found out one last bit of info for anyone who might ever use the  waveform generator waveform.exe:
This program gives the user the option to specify the width and height of the .png file, which causes the waveform
to shrink or stretch and this can be useful to get longer sound spikes. In effect, you raise the amplitude of the .png graphic representation w/o
having to run waveform again!

By the way, I noticed my typo error in this thread title. Thanks again. I'll keep tabs on this forum. Sorry about my
excess of enthusiasm but Waveform is
a gem! So is Lazarus, C, Delphi and Pascal. I also saw a function in C code
that makes some nice spikes.
Title: Re: Bitmap wavefore from .wav file
Post by: BigChimp on April 07, 2014, 12:34:43 pm
Forgive me if I"m less than enthusiastic about a third party exe rather than a native Lazarus/FPC solution... but glad you got what you needed!
Title: Re: Bitmap wavefore from .wav file
Post by: user5 on April 08, 2014, 05:33:29 pm
Well, you are absolutely correct and my enthusiasm has dimmed, but I was desperate. This is the last stumbling block against continuing forward with my program. Not only that, but using this particular executable causes a blank window to appear and disappear plus the fact that Lazarus won’t allow some commands to heep it hidden (using recorder and TProcessUTF8). I may search again for something more code related but it’s hard; there’s a real propietary attitude out there and good info is the hardest to get. All I really need is a simple VU meter to get the highs and lows of speech and I could do the rest using time itself to make a decent and desirably simple wave. Thanks for your comments, which made me thoughtful.
Title: Re: Bitmap wavefore from .wav file
Post by: BigChimp on April 08, 2014, 05:55:21 pm
Proprietary? I don't see that at all.

Just check out the forum link to uos which is open source.

Also karaba explained a way to do things... I'm sure that you'll get all the help you need if you start implementing this yourself...
Title: Re: Bitmap wavefore from .wav file
Post by: Fred vS on April 08, 2014, 06:42:01 pm
Quote
perhaps that lib has other demo programs/controls that can show waveforms already...

=> https://github.com/fredvs/uos (https://github.com/fredvs/uos) => /uos/examples/WaveForm.lpi

 ;)
Title: Re: Bitmap wavefore from .wav file
Post by: user5 on April 08, 2014, 11:36:11 pm
I know what Karaba was talking about but the problem isn’t there, it’s in getting those plot points in the first place and the only way I can see to do that is either to read and decipher the wave file itself, which I and most others don’t know how to do, or to sample the wave file as it’s playing to get its changing volume. I’ve seen things like API GetWaveOutVolume and such but I think that refers to the sound card and windows mixer settings, not the wave itself. I did manage to get the open source for Audorra and it has 2 VU meters in it, but the simplest example of its player package is missing some units which I haven’t been able to find, namely auwave.pas, auwaveformat.pas and possibly others. I did manage to get some other Audorra demos to run and that’s a feat right there but I’ll check out your suggestions. Thanks again.

PS: I did download uos and tried to run it in Lazarus but when I tried to compile it I got an error message that said an illegal qualifier was being used. The line of code (in uos.pas) involved was: setlength(uosLevelArray[index].[InputIndex],0) ;  The cursor stopped at [InputIndex] This also happened with the waveform demo. Maybe I’m using the wrong version of Lazarus (1.0.10). I’m going to download Lazarus 1.2 and then I’ll try again.
Title: Re: Bitmap wavefore from .wav file
Post by: Fred vS on April 08, 2014, 11:42:18 pm
Quote
S: I did download uos and tried to run it in Lazarus but when I tried to compile it I got an error message that said an illegal qualifier was being used. The line of code (in uos.pas) involved was: setlength(uosLevelArray[index].[InputIndex],0) ;  The

Hum, what system are you using ? (Windows, osx, Linux ?)

[EDIT] Have you try to compile waveform.lpi ?
Title: Re: Bitmap wavefore from .wav file
Post by: Fred vS on April 08, 2014, 11:54:46 pm
Quote
Quote

    S: I did download uos and tried to run it in Lazarus but when I tried to compile it I got an error message that said an illegal qualifier was being used. The line of code (in uos.pas) involved was: setlength(uosLevelArray[index].[InputIndex],0) ;  The


Hum, what system are you using ? (Windows, osx, Linux ?)

[EDIT] Have you try to compile waveform.lpi ?

Hum, just tested on Windows and it works too.

PS : Do not use Debugger (too much calculation for him  :-X) and compile waveform.lpi
Title: Re: Bitmap wavefore from .wav file
Post by: Fred vS on April 09, 2014, 01:42:22 am
Quote
The line of code (in uos.pas) involved was: setlength(uosLevelArray[index].[InputIndex],0) ;  The cursor stopped at [InputIndex] This also happened with the waveform demo. Maybe I’m using the wrong version of Lazarus (1.0.10).

Oops, i see what append => you are using fpc 2.6.2.

Im using fpc 2.7.1.

=> I will ask some help to forum...
Title: Re: Bitmap wavefore from .wav file
Post by: skalogryz on April 09, 2014, 04:33:26 am
Let me step on Fred vS toes (again) and suggest to use openal wav playback test :)

The reason - it has .wav loader.
Strip all the openal playback code and just paint the waveform ... hmm to a TBitmap.
Title: Re: Bitmap wavefore from .wav file
Post by: Fred vS on April 09, 2014, 04:51:10 am
Quote
Let me step on Fred vS toes (again) and suggest to use openal wav playback test :)

 ;)

Hum, by the way, im very interested by the .wav loader...
Could you give me some info about it ?  :-X
Title: Re: Bitmap wavefore from .wav file
Post by: Fred vS on April 09, 2014, 05:12:41 am
Quote
S: I did download uos and tried to run it in Lazarus but when I tried to compile it I got an error message that said an illegal qualifier was being used. The line of code (in uos.pas) involved was: setlength(uosLevelArray[index].[InputIndex],0) ;  The

Updated waveform example compatible with fpc 2.6.2.
=> https://github.com/fredvs/uos (https://github.com/fredvs/uos) => /uos/examples/WaveForm.lpi

Title: Re: Bitmap wavefore from .wav file
Post by: skalogryz on April 09, 2014, 05:41:50 am
Hum, by the way, im very interested by the .wav loader...
Could you give me some info about it ?  :-X
TWaveReader class at wavopenal.pas (http://svn.freepascal.org/svn/fpc/trunk/packages/openal/examples/wavopenal.pas)
a simple wav loader based on wav specs (http://en.wikipedia.org/wiki/Wav). Actually there're plenty of specifications online on various sites.

Currently it just reads through the wav and returns you waves data (no conversion is done).
Thus , if you need 16-bit stereo wave for payback and the wav file is 8-bit mono, it would be up to your code to convert it.
Any compression is obviously not supported (though compressed wavs are quire rare).

Btw, that makes it really easy to use for waveform rendering. Just read a chunk and build the waveform based on how many milliseconds fits into X pixels.

P.S. there're rumors that fpc team are going to create some kind of fcl package to handle audio hardware and file formats.

Title: Re: Bitmap wavefore from .wav file
Post by: Fred vS on April 09, 2014, 12:15:51 pm
Quote
P.S. there're rumors that fpc team are going to create some kind of fcl package to handle audio hardware and file formats.

Hum, im very curious, mainly for the  audio hardware part.  ;)
Title: Re: Bitmap wavefore from .wav file
Post by: BigChimp on April 09, 2014, 12:20:40 pm
Why? What's so exciting about sound cards ;)
Title: Re: Bitmap wavefore from .wav file
Post by: BigChimp on April 09, 2014, 12:22:10 pm
P.S. there're rumors that fpc team are going to create some kind of fcl package to handle audio hardware and file formats.
Rumors?
Are you referring to this
http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/packages/fcl-sound/
;)
Title: Re: Bitmap wavefore from .wav file
Post by: Fred vS on April 09, 2014, 12:24:54 pm
Quote
Why? What's so exciting about sound cards ;)

Hum, because all the audio lib that i try that do not use portaudio library are not fully 100 % good working and not really cross-platform...  :-X

[EDIT] Bass appart, of course, Bass is working perfectly everywhere (but is not open-source).



Title: Re: Bitmap wavefore from .wav file
Post by: BigChimp on April 09, 2014, 12:31:47 pm
Ah ;)
Title: Re: Bitmap wavefore from .wav file
Post by: skalogryz on April 09, 2014, 02:18:12 pm
Are you referring to this
http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/packages/fcl-sound/
;)
yes. that's exactly what i'm talking about.

Title: Re: Bitmap wavefore from .wav file
Post by: Fred vS on April 09, 2014, 04:29:26 pm
Quote
Quote from: BigChimp on Today at 12:22:10 pm

    Are you referring to this
    http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/packages/fcl-sound/
    ;)

yes. that's exactly what i'm talking about.

Ok, i promise not to tell  :-X

Hum, what fcl-sound can (will) do ?
Title: Re: Bitmap wavefore from .wav file
Post by: skalogryz on April 09, 2014, 04:48:06 pm
Ok, i promise not to tell  :-X

Hum, what fcl-sound can (will) do ?
everything and probably more than uos.
Title: Re: Bitmap wavefore from .wav file
Post by: BigChimp on April 09, 2014, 04:53:13 pm
everything and probably more than uos.
sudo make me a sandwich then ;)

Sorry, could not resist...
Title: Re: Bitmap wavefore from .wav file
Post by: Fred vS on April 09, 2014, 09:18:30 pm
Quote
everything and probably more than uos.

Wow, nice, and with post-fractalization in tri-turbo mode too ?  :-X
Title: Re: Bitmap wavefore from .wav file
Post by: user5 on April 10, 2014, 04:02:01 pm
Hi! Remember me? I’m the newbie who started this thread and it’s been real interesting. I’ve read every post. I’m looking for a way to ‘simply’ sample playing soundtracks or to make a wave. I’m surprised that there doesn’t seem to be a procedure for doing that in Lazarus, Delphi or API. Tried a lot of stuff but most downloads are incomplete or just don’t work. Found an exec, waveform.exe, that does the job but it’s not an elegant solution. Open source Audorra is real nice and I may include it with my program as an extra. I found the part of its code that does the sampling and I could save the info in an array or something but I can’t think of a way to get the info out of the program. Lazarus won’t let me use text files with this application, but it just occurred to me that I could write directly to a .bmp. Hmmmm... Will post again when I learn more.

PS: I downloaded Lazarus 1.2 but I had some trouble with it so I went back to my earlier version and I was surprised to notice that it uses fpc 2.6.2 just like Lazarus 1.0, if I’m correct on that. I’d like to have fpc 2.7 but I think I’ll wait on that. I couldn’t get uos to work, apparently because I don’t have fpc 2.7 or because of some encoding issue when I saved uos.pas from Notepad into my directory so it was real cruel of  you to post that very nice waveform graphic from uos.

Love this forum but I think some of you could run rings around me, though I know what I need to know to get my program done except for, of course, sampling a playing wave.
I’m surprised that no one has asked me what my program does. I think that’s courtesy on your part. If someone asks I’ll tell ‘em. That’s the least that I can do for getting a nice welcome. Thanx.
Title: Re: Bitmap wavefore from .wav file
Post by: BigChimp on April 10, 2014, 05:04:05 pm
Welll... have you read this:
Updated waveform example compatible with fpc 2.6.2.
=> https://github.com/fredvs/uos (https://github.com/fredvs/uos) => /uos/examples/WaveForm.lpi

Enjoy :)

PS: What does your program do? :)
Title: Re: Bitmap wavefore from .wav file
Post by: Fred vS on April 10, 2014, 05:31:12 pm
Quote
Welll... have you read this:
;)

@  user5, if you want to try uos, here how to do :

1) Go on uos Github site =>  https://github.com/fredvs/uos  (https://github.com/fredvs/uos)
2) Click on button "Download ZIP".
3) Unzip-it.
4) Run Lazarus.
5) In "Project" => "Open Project" choose /uos/examples/waveform.lpi
6) Compile and Run it...
Title: Re: Bitmap wavefore from .wav file
Post by: user5 on April 10, 2014, 06:19:49 pm
Like I said, I tried to compile waveform.lpi before, but it uses uos_flat and uos_flat uses uos.pas and uos.pas won’t compile because of an illegal qualifier or because I don’t have fpc 2.7 or for some other reason. My compiler says that its because of an illegal qualifier. At your suggestion I once again copied uos.pas and directly pasted it into Lazarus instead of using Notepad.

It still won’t compile! The other units compile fine. Not only that, but now I realize that Audorra shows an .exe pop up window, just like waveform.exe. If I have to suffer with a dummy doslike window like that then I’ll go with waveform.exe since it does it all and even allows me to lengthen the waveform spikes. I checked and unchecked the the project-options-linking-win32 gui box but to no avail. I used to know a compiler directive header that gets rid of that window but I can’t remember or find it. Even then I experienced some unexpected results.

Replacing Lazarus1.0.10\fpc\2.6.2 with fpc 2.7 is real tricky and I’m just too busy right now.
Title: Re: Bitmap wavefore from .wav file
Post by: user5 on April 10, 2014, 06:34:25 pm
Fred vs, something you had in your footnotes got my attention, the fact that you use Lazarus 1.1. When I tried to make a package using my new copy of Lazarus 1.2, it crashed but I never did try to run waveform.lpi on it. I’m going to install it again and try to compile waveform once more. Thanks
Title: Re: Bitmap wavefore from .wav file
Post by: user5 on April 10, 2014, 07:09:09 pm
Unfortunately, uos won’t compile for me with Lazarus 1.0.10 or 1.2, bacause of an “illegal qualifier” error. That’s the way it goes sometimes.
Title: Re: Bitmap wavefore from .wav file
Post by: taazz on April 10, 2014, 08:48:15 pm
1) make sure you used the proper download procedure. Don't copy paste from your browser.
2) make sure all needed files are present and can be found.
3) if the package provides a test suit use it to make sure that everything works as expected before installing.
4) please post all the relevant information for the error eg line number and that line too.

Saying I get an “illegal qualifier” error its the same as telling a doctor that you have a pain.
Title: Re: Bitmap wavefore from .wav file
Post by: Fred vS on April 10, 2014, 08:55:36 pm
@ user5 => Please, download the NEW release of uos (version : 130140410).
=> in uos.pas =>
Code: [Select]
const
  uos_version : LongInt = 130140410 ;

Do not use old release =>

1) Go on uos Github site => https://github.com/fredvs/uos (https://github.com/fredvs/uos)
2) Click on button "Download ZIP". => on right side, in the middle of page
3) Unzip uos-master.zip.
4) Run Lazarus.
5) In "Project" => "Open Project" choose ../uos-master/examples/waveform.lpi
6) Compile and Run it (without Debugger => too much calculation for him)...

With that new release, you may use fpc 2.6.2.
Title: Re: Bitmap wavefore from .wav file
Post by: user5 on April 11, 2014, 09:24:36 am
taazz, if you had checked some earlier posts of mine first, you would have seen one that indeed listed the relevant line of code, along with the error message. I think it’s only about 20 posts back in this thread. It’s true that I didn’t list its line number but all you needed to do was to copy and paste it and then do a search through the units. There are only 3 of ‘em. I would list the ‘offending’ code here again but I got a pain, Doc.

Fred vs, you are super duper. I downloaded the zip and Waveform works fine now. I didn’t see the zip option before and thought my only option was to copy and paste. The zip option was tucked way out of view and there was no mention of such a file anywhere else on the page. Waveform looks like a good deal but it’s got some quirks and it seems tailored to the higher frequencies rather than speech, though I might be able to use it. Thanks again for your patience and understanding. You’re a steely-eyed missile man.

Does anyone know if Audacity can save a wave file into a .png or not? I could have sworn that I exported a wave file into a .png using Audacity but now there are no file types AT ALL in the “Save as file type” drop down menu. There should be 1 or 2 there, right? I’m using one of the first versions of Audacity (.95) ‘cause I wanted a small program. It’s driving me crazy.
Title: Re: Bitmap wavefore from .wav file
Post by: taazz on April 11, 2014, 08:51:45 pm
taazz, if you had checked some earlier posts of mine first, you would have seen one that indeed listed the relevant line of code, along with the error message. I think it’s only about 20 posts back in this thread. It’s true that I didn’t list its line number but all you needed to do was to copy and paste it and then do a search through the units. There are only 3 of ‘em. I would list the ‘offending’ code here again but I got a pain, Doc.


If you had payed attention you would have known that the specific problem was solved already with the help of Martin_FR in this forums and a new version was uploaded before fred asked you to try again, the problem is that you leave out important information and I guess at this point you left out the step to download the new version too.
Title: Re: Bitmap wavefore from .wav file
Post by: user5 on April 12, 2014, 12:45:56 am
Nonsense. Is this a test or something? I can easily refute ya and a careful reading of your previous note speaks for itself but I’ll do you the favor of letting you have the last word if you’ll do me the favor of not posting on any now doubtful future posts of mine. It’s not my purpose to get caught up in any proprietary contests. My purpose is to forge ahead with my program and to thank this forum for its great help and to make sure that I give proper credits and acknowledgements to uos and others. I did some more sound testing of the uos makeform code and I have to say that it just might be perfect for me. I will never forget this help to me or you. Reach for the stars!
TinyPortal © 2005-2018