Page 1 of 1

Cropping TWave

PostPosted: April 1st, 2007, 12:25 pm
by stfine
Hello. Thank you for the Wave Package - I use it a lot.

But now I have stumbled with cropping a wave loaded into TWave with a 1 sample accuracy. TWave.Delete takes a Pos argument in milliseconds and that provides only 44 sample resolution for 44100Hz audio stream. How can I delete, say, from 2000th sample to the end of file?

BTW, I didn't understand completely what is TWave.Crop intended for.

Thanks.

PostPosted: April 1st, 2007, 6:15 pm
by Kambiz
To delete end of a wave audio from a position specified by the Pos variable use:

Wave.Delete(Pos, Wave.Length - Pos);

Consider that converting milliseconds to samples is approximated.

Regarding Crop method, suppose in a stream there is a wave audio appended with some other data, the Crop method removes the non-audio data.

PostPosted: April 1st, 2007, 7:26 pm
by stfine
Kambiz wrote:Consider that converting milliseconds to samples is approximated.


Dear Kambiz, I need to specify EXACT sample number, not approximated. If we have 44100 samples per second, that is approx. 44 samples per a millisecond. As I understood, Delete(1,1) corresponds to deleting 44 samples from offset 44. I'd rather have function that take sample numbers as arguments.

Example: to delete 50 samples from sample number 100.

PostPosted: April 2nd, 2007, 8:57 am
by Kambiz
It means changing the average samples per second, and implies changing the wave format.

PostPosted: April 2nd, 2007, 4:53 pm
by stfine
It doesn't mean changing the average samples per second. For instance, if delete 1 sample from the beginning of the wave, how does it affects wave description? In no way. I just have deleted 0,023ms of sound.

Let me restate my request - the current realization is tailored to work with 1ms precision, while I want to manipulate wave with 1 sample precision.

I though about working with underlying TMemoryStream directly, but then I need somehow to update TWave fileds to reflect that changes. It seems to me not easier then bothering with Windows API functions without TWave class at all.

:roll:

PostPosted: April 2nd, 2007, 9:53 pm
by Kambiz
If you look at Delete code, you will find out how to change wave data directly. It's easier to subclass TWave and introduce a new delete method for your purpose.