How to update the lengthInSamples foraudioFormatReaderSource

Hi, juce
How is it going?
In audioFormatReader, it has a public data member lengthInSamples.
I can update it directly.

I use AudioFormatReaderSource (AudioFormatReader *const sourceReader, const bool deleteReaderWhenThisIsDeleted)
to initialize a audioFormatReaderSource, and keep it in one class as a data member,

then use audioTransportSource.setSource() to initialize the audioTransportSource.

I want to update lengthInSamples in audioTransportSource or audioFormatReaderSource objs later in my application. Is there any way to do it? I do not find the member functions to update lengthInSamples.

Thanks!
Leon

Juce is an abstract concept, not a person… (?)

Why? If a file is is use by a reader, then you won’t be able to write to it. So the length can’t change…

hi, jules
Sorry for bad calling.

Make sense. If I want to update the length in this scenario, any way to do it?

Thanks!
Leon

I don’t understand the scenario you’re talking about… Like I said, you won’t be able to alter the file while it’s in use, so how could its length possibly change? Or maybe I’ve completely misunderstood what you’re asking?

hi, jules
there is sequence I implmented:
1.juce::File audioFile(filePath);
2.audioFormatReader(m_formatManager.createReaderFor(audioFile));
3.audioFormatReader->lengthInSamples = newlengthInSamples
4.audioFormatReaderSource(audioFormatReader);
5.audioTransportSource.setSource(audioFormatReaderSource);

I updated the lengthInSamples in step3, before we initialize the transport.It works.
I am asking if we can update the lengthInSamples after step 5. we use the same file, and I want to just reset the length without doing the all 5 steps again.
I want to add two functions in audioTransportSource class, set and get, to modify the lengthInSample. However, I am not sure it will work or not.
As you said, it will not work in this way.
Is this clear? :slight_smile:

Thanks!
Leon

What on earth are you trying to do?? If you’re trying to play just the initial section of the file, then put it through an AudioSubsectionReader, don’t go messing with read-only values!

AudioFormatReaderSource has a method called “getAuduioFormatReader()”. U can use this method to get the “AudioFormatReader” and set its length.
Or
U can use ur own class which is inherited from the “AudioTransportSource” and have the pointer for the “AudioformatReaderSource” object. Having the object of the “AudioFormatReaderSource” in ur derived class u can set the length of the reader by calling

And as Jules said dont try to modify the length of the reader. U will loose the original length permanently so be careful while changing the length of the reader. Use AudioSubsectionReder instead. :frowning:

hi, Godwin
Thanks for your reply!
Yes, I tried to use the AudioSubsectionReader after jules told me this , and it works good in my application.

Cheers!
Leon