Page 1 of 1

How to play a part of an audio file ?

PostPosted: February 21st, 2008, 4:03 pm
by stef
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

PostPosted: February 21st, 2008, 9:08 pm
by Kambiz
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.

PostPosted: February 22nd, 2008, 8:45 am
by stef
thanks Kambiz,

cheers,
Stef

PostPosted: February 25th, 2008, 11:10 am
by Kambiz
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);

PostPosted: February 27th, 2008, 7:15 pm
by stef
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

PostPosted: February 27th, 2008, 8:55 pm
by Kambiz
I did run Mixer Control demo on my Vista box with no problem. :?

PostPosted: February 27th, 2008, 11:51 pm
by stef
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

PostPosted: February 29th, 2008, 6:30 pm
by stef
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

PostPosted: March 3rd, 2008, 4:56 pm
by stef
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

PostPosted: March 4th, 2008, 5:35 pm
by Kambiz
Having a sample to trace the problem would be very helpful.

PostPosted: March 4th, 2008, 10:20 pm
by stef
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

PostPosted: March 5th, 2008, 11:08 am
by stef
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

PostPosted: March 8th, 2008, 9:17 pm
by Kambiz
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.

PostPosted: March 14th, 2008, 6:46 pm
by Kambiz
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?