How to play a part of an audio file ?

Please post bug reports, feature requests, or any question regarding the DELPHI AREA products here.

How to play a part of an audio file ?

Postby stef » February 21st, 2008, 4:03 pm

hello,

I just started with waveaudio package,
and succeeded in making a recording.

For simple task like recording and playback,
I find the manual quit complex.
So I couldn't find a simple solution (without understanding the complete manual) for my second problem: playing (and displaying) a small part of the recorded signal. I know the start and end times in milliseconds, but then ...

// load the audio file
WaveStorage.Wave.LoadFromFile('D:\Data_TO_exe\aap.wav');

// get the audio length in msec
Nsamp := WaveStorage.Wave.Length ;

// make a copy so we can use a different part later
WaveStorage_part.WaveStream[0].CopyFrom(WaveStorage.WaveStream[0],0);

// delete the end of the audio, that we don't need
// Nsamp is too large but it looks it's accepted
WaveStorage_part.Wave.Delete(5000,Nsamp);
// delete the beginning
WaveStorage_part.Wave.Delete(0,3000);

// so now we have the part to be played and displayed
StockAudioPlayer1.PlayStream ( WaveStorage_part.WaveStream[0] ) ;

I sthis the correct way of doing it, or are there better / simpler ways ?

What's the difference between
Wavestream[0]
and
Wave
they seem to do the same ??

thanks,
Stef Mientki
stef
Active Member
Active Member
 
Posts: 18
Joined: July 15th, 2007, 1:35 pm

Postby Kambiz » February 21st, 2008, 9:08 pm

That's correct. Alternatively you can set the position of player to desired start position of the audio. Then during playback, when position reached to the stop position, stop the player.

Wave and Wavestream[0] properties of TWaveStorage point to same object. Wavestream[0] property of TWave class is for compatibility with TWaveCollection.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Postby stef » February 22nd, 2008, 8:45 am

thanks Kambiz,

cheers,
Stef
stef
Active Member
Active Member
 
Posts: 18
Joined: July 15th, 2007, 1:35 pm

Postby Kambiz » February 25th, 2008, 11:10 am

I update Wave Audio package to add some new methods to TWaveStreamAdapter class.

One of these methods is Copy. Using this method you can create a portion of original wave easily.

For example:

Code: Select all
WaveStorage.Wave.LoadFromFile('D:\Data_TO_exe\aap.wav');
WaveStorage_part.Wave.Copy(WaveStorage.Wave, 3000, 2000);


Or using Sub method:

Code: Select all
WaveStorage_part.Wave.LoadFromFile('D:\Data_TO_exe\aap.wav');
WaveStorage_part.Wave.Sub(3000, 2000);
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Postby stef » February 27th, 2008, 7:15 pm

thanks Kambiz,

that's certainly a valuable addition.

I've been struggling the last days with your mixer component,
I couldn't get it to work reliable on more than 1 machine (all XP),
and it crashed terrible on Vista (but I guess that's due to some major changes in Vista). So I had to go back to my old mixer component (Amixer, also called tAudioMixer, so I had to remove it from your library and rewrite my code. As the mixer component is a rather complex / system dependant component (at least from my point of view), it might be a good idea to add a demo (like in amixer), so the user can quickly see if the mixer works for his soundcard.

cheers,
Stef
stef
Active Member
Active Member
 
Posts: 18
Joined: July 15th, 2007, 1:35 pm

Postby Kambiz » February 27th, 2008, 8:55 pm

I did run Mixer Control demo on my Vista box with no problem. :?
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Postby stef » February 27th, 2008, 11:51 pm

thanks,

sorry I forgot all about that demo,
as soon as I've a vista machine available,
I'll certainly test that,
and I'll report back.

cheers,
Stef
stef
Active Member
Active Member
 
Posts: 18
Joined: July 15th, 2007, 1:35 pm

Postby stef » February 29th, 2008, 6:30 pm

sorry sorry sorry, Kambiz,

it was all my fault,
your demo of the mixer (and now mine too ;-) runs perfectly well,
both under XP and Vista,
tested several cards range from over 5 years old to very modern ones.

One of the problems is that Vista has a new philosophy about mixers,
so I've to get used to that.

thanks for the very good component
(much simpeler (after you understand it ;-) than the one I used before),
cheers,
Stef Mientki
stef
Active Member
Active Member
 
Posts: 18
Joined: July 15th, 2007, 1:35 pm

Postby stef » March 3rd, 2008, 4:56 pm

hi Kambiz,

Thanks for the fast bugfix ...

... but the recording problem (a buffer is stored twice) is still there,
probably has been there all the time,
but I didn't notice it until now.

My program works like this:
- an image is shown
- the child should pronounce the issue on the image
- these steps are repeated about 50 times
I use StockAudioRecorder, because it was used in your example,
and because it has a recordtofile.

When I load a new image, the recording isn't stopped.
When using large images, the number of errors increases.
When I increase the buffersize of the recorder, the number of errors decreases (maybe even vanishes at 10000 ),
but as I need to know the pointers were a certain image was shown,
10000 is too long,
because when asking the recorder for it's position,
(at least I guess) the recorder waits until the buffer is finished.

I also tried to increase the number of buffers,
but that didn't reduce the error rate.

I also tried to pause the recording before loading a new image,
(see the last recording in the attachment),
and that resulted in an "echo" of almost every word.

I hope my comment will help you to find the bug,
let me know if you need more information.
If it's necessary,
I think I can simplify my program,
so I can send it to you for debugging.

cheers,
Stef
Attachments
waveaudio_problem.pdf
some recordings
(184.74 KiB) Downloaded 148 times
stef
Active Member
Active Member
 
Posts: 18
Joined: July 15th, 2007, 1:35 pm

Postby Kambiz » March 4th, 2008, 5:35 pm

Having a sample to trace the problem would be very helpful.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Postby stef » March 4th, 2008, 10:20 pm

hi Kambiz,

I created a simple example,
reproducing the problem.
I don't have it around with me now,
so I'll send it tomorrow.

thanks for your respons.

cheers,
Stef
stef
Active Member
Active Member
 
Posts: 18
Joined: July 15th, 2007, 1:35 pm

Postby stef » March 5th, 2008, 11:08 am

hi Kambiz,

this is a very simple example (D7) that shows the problem.
The program shows a picture,
then you have to pronounce the object,
with the spacebar you go to the next picture,
and so on.
With escape you leave the program.

You need 2 large (600k or larger) jpeg pictures (not included),
named
auto_2.jpg
bal_2.jpg
or change the name in the program.

Hope this helps you to solve the problem,
(I'm not in a hurry, because I now use another approach).

cheers,
Stef
Attachments
test_sound_opname.zip
(1.5 KiB) Downloaded 174 times
stef
Active Member
Active Member
 
Posts: 18
Joined: July 15th, 2007, 1:35 pm

Postby Kambiz » March 8th, 2008, 9:17 pm

Thanks for the sample. It's very good that you are not in harry. :)

I was too busy for a few says, so that I couldn't even get online. I try to find and resolve the problem until weekend.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Postby Kambiz » March 14th, 2008, 6:46 pm

Hi Stef,

I checked your sample out. On my machine it works properly.

Even I used PicShow and better audio format to use more cpu, but no change in quality of recorded voice.

I see other people have downloaded your sample. Any feedback?
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm


Return to DELPHI AREA Products

Who is online

Users browsing this forum: Bing [Bot] and 1 guest